Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract values in Pandas value_counts()

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]

like image 250
JamesButterlips Avatar asked Feb 20 '16 13:02

JamesButterlips


People also ask

What does Value_counts () do in pandas?

Return a Series containing counts of unique values. The resulting object will be in descending order so that the first element is the most frequently-occurring element.

How do you get value counts pandas?

syntax to use value_counts on a Pandas dataframe This is really simple. You just type the name of the dataframe then . value_counts() . When you use value_counts on a dataframe, it will count the number of records for every combination of unique values for every column.

What type does Value_counts return?

1. ) The value_counts function returns the count of all unique values in the given index in descending order without any null values.

What is the difference between Value_counts and count in pandas?

count() should be used when you want to find the frequency of valid values present in columns with respect to specified col . . value_counts() should be used to find the frequencies of a series.


1 Answers

Try this:

dataframe[column].value_counts().index.tolist() ['apple', 'sausage', 'banana', 'cheese'] 
like image 150
Mike Müller Avatar answered Sep 22 '22 06:09

Mike Müller