I use pandas's value_counts() method to get the number of times each value in a column appears. Although the output looks like what I expected, attempting to save it using numpy savetxt or pandas to_csv returns only one column (with counts). I'd like to be able to save both.
One way would be to use reset_index and then to_csv
df['key'].value_counts().reset_index().to_csv('df.csv')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With