0

I am unique values from a very long list. For example

Column_1
apple
orange
pear
banana
pear
apple
apple

if I type:

file['Column_1'].value_counts()

it returns a single column

apple 3
pear 2
orange 1
banana 1

I would like to to be two columns so I use matplotlib to graph the results.

apple, 3
pear, 2
orange, 1
banana, 1

Any advice?

  • The return from `value_counts` is a `Series` I would recommend [this answer](https://stackoverflow.com/a/53686321/15497888) which can handle both renaming the column and turning it back into a DataFrame. `file['Column_1'].value_counts().reset_index(name='Counts')` – Henry Ecker Sep 10 '21 at 04:35
  • You might also find [Using Pandas Value_Counts and matplotlib](https://stackoverflow.com/q/36762199/15497888)/[Sorted bar charts with pandas/matplotlib or seaborn](https://stackoverflow.com/q/28022227/15497888) helpful. – Henry Ecker Sep 10 '21 at 04:38

0 Answers0