I'm trying to write the keys and values of a dictionary in a .csv file for the first time. I'd like two have two columns: A) keys and B) values.
I used NLTK to get the bigrams from a large text file:
frequency=nltk.FreqDist(bigrams)
The dictionary looks like this:
('word1', 'word2'),1
I'd like to write the most common, say 100 bigrams, into the .csv file. My code looks like this:
import pandas as pd
import csv
common=frequency.most_common(100)
pd.DataFrame(common, columns=['word', 'count']).to_csv("output.csv", index=False)
However, the results are not being written in two different columns (A and B), they are all written in the same column (column A)
How can I fix this? Thanks!