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]
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.
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.
1. ) The value_counts function returns the count of all unique values in the given index in descending order without any null values.
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.
Try this:
dataframe[column].value_counts().index.tolist() ['apple', 'sausage', 'banana', 'cheese']
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