DataFrame.
value_counts
Return a Series containing counts of unique rows in the DataFrame.
New in version 1.1.0.
Columns to use when counting unique combinations.
Return proportions rather than frequencies.
Sort by frequencies.
Sort in ascending order.
See also
Series.value_counts
Equivalent method on Series.
Notes
The returned Series will have a MultiIndex with one level per input column. By default, rows that contain any NA values are omitted from the result. By default, the resulting Series will be in descending order so that the first element is the most frequently-occurring row.
Examples
>>> df = pd.DataFrame({'num_legs': [2, 4, 4, 6], ... 'num_wings': [2, 0, 0, 0]}, ... index=['falcon', 'dog', 'cat', 'ant']) >>> df num_legs num_wings falcon 2 2 dog 4 0 cat 4 0 ant 6 0
>>> df.value_counts() num_legs num_wings 4 0 2 6 0 1 2 2 1 dtype: int64
>>> df.value_counts(sort=False) num_legs num_wings 2 2 1 4 0 2 6 0 1 dtype: int64
>>> df.value_counts(ascending=True) num_legs num_wings 2 2 1 6 0 1 4 0 2 dtype: int64
>>> df.value_counts(normalize=True) num_legs num_wings 4 0 0.50 6 0 0.25 2 2 0.25 dtype: float64