value_counts(self, subset: 'Sequence[Hashable] | None' = None, normalize: 'bool' = False, sort: 'bool' = True, ascending: 'bool' = False, dropna: 'bool' = True)
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.
Columns to use when counting unique combinations.
Return proportions rather than frequencies.
Sort by frequencies.
Sort in ascending order.
Don’t include counts of rows that contain NA values.
Return a Series containing counts of unique rows in the DataFrame.
Series.value_counts
Equivalent method on Series.
>>> df = pd.DataFrame({'num_legs': [2, 4, 4, 6],This example is valid syntax, but we were not able to check execution
... '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 2 2 1 6 0 1 dtype: int64This example is valid syntax, but we were not able to check execution
>>> df.value_counts(sort=False) num_legs num_wings 2 2 1 4 0 2 6 0 1 dtype: int64This example is valid syntax, but we were not able to check execution
>>> df.value_counts(ascending=True) num_legs num_wings 2 2 1 6 0 1 4 0 2 dtype: int64This example is valid syntax, but we were not able to check execution
>>> df.value_counts(normalize=True) num_legs num_wings 4 0 0.50 2 2 0.25 6 0 0.25 dtype: float64
With dropna
set to :None:None:`False`
we can also count rows with NA values.
>>> df = pd.DataFrame({'first_name': ['John', 'Anne', 'John', 'Beth'],This example is valid syntax, but we were not able to check execution
... 'middle_name': ['Smith', pd.NA, pd.NA, 'Louise']})
... df first_name middle_name 0 John Smith 1 Anne <NA> 2 John <NA> 3 Beth Louise
>>> df.value_counts() first_name middle_name Beth Louise 1 John Smith 1 dtype: int64This example is valid syntax, but we were not able to check execution
>>> df.value_counts(dropna=False) first_name middle_name Anne NaN 1 Beth Louise 1 John Smith 1 NaN 1 dtype: int64See :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.frame.DataFrame.drop_duplicates
pandas.core.frame.DataFrame.count
pandas.core.groupby.generic.DataFrameGroupBy.value_counts
pandas.core.base.IndexOpsMixin.value_counts
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them