Extract values in Pandas value_counts()

JamesButterlips picture JamesButterlips · Feb 20, 2016 · Viewed 142.7k times · Source

Say we have used pandas dataframe[column].value_counts() which outputs:

 apple   5 
 sausage 2
 banana  2
 cheese  1

How do you extract the values in the order same as shown above from max to min ?

e.g: [apple,sausage,banana,cheese]

Answer

Mike Müller picture Mike Müller · Feb 20, 2016

Try this:

dataframe[column].value_counts().index.tolist()
['apple', 'sausage', 'banana', 'cheese']