Context
I am trying to export value_counts of a dataframe to a csv.
Blocker
The code below generate 2 columns, key and values.
[3]: https://i.stack.imgur.com/2Xw4S.png
What is the best way to export to csv? I've tried converting to dataframe, but this doesn't produce an appropriate output.
# load data
df = sns.load_dataset('mpg')
# View input dataframe
df.head()
# convert value counts to a dataframe
freq = {}
for c in df.columns:
fre= df[c].value_counts()
freq[c] = fre
ff = pd.DataFrame(freq.items())
# View output dataframe
print(ff)
# export dataframe to csv
ff.to_csv(file_path)