Create a csv file with two columns | Counter mode
<p>I worked on a code that is counting the occurrencies of words in a given text document and now I would like to save the output on a csv file with two columns: one for the words and one for their frequencies.</p>

<p>This is the code that I am trying to replicate:</p>

<pre><code>from collections import Counter
counter = Counter(['spam', 'egg', 'spam', 'egg', 'python', 'egg'])

with open('wordfile.csv', 'w') as f:
    writer = csv.writer(f, delimiter=' ')
    writer.writerow(('word', 'count'))
    writer.writerows(counter.most_common())     
</code></pre>

<p>However, this is the output:</p>

<pre><code>word countegg 3spam 2python 1
</code></pre>

<p>The output that I am trying to get should contain just two columns (one for the "word" adn one for the "frequency" and each row should contain a word and its occurrance in the text:</p>

<pre><code>word, frequency,
the, 3165,
in, 1265,
of,1233,
</code></pre>

<p>When I print the output with the code:</p>

<pre><code>print(open('wordfile.csv', 'rb').read())
</code></pre>

<p>I get:</p>

<pre><code>b'word count\r\r\negg 3\r\r\nspam 2\r\r\npython 1\r\r\n')
</code></pre>

<p>As you can see there aren't the two columns for the word and the frequency.
I am using Windows and this is the Python version that I am using: 
3.5.2 |Anaconda 4.1.1 (64-bit)</p>