pandas 1.4.2

ParametersReturns
value_counts(self, normalize: 'bool' = False, sort: 'bool' = True, ascending: 'bool' = False, bins=None, dropna: 'bool' = True)

The resulting object will be in descending order so that the first element is the most frequently-occurring element. Excludes NA values by default.

Parameters

normalize : bool, default False

If True then the object returned will contain the relative frequencies of the unique values.

sort : bool, default True

Sort by frequencies.

ascending : bool, default False

Sort in ascending order.

bins : int, optional

Rather than count values, group them into half-open bins, a convenience for pd.cut , only works with numeric data.

dropna : bool, default True

Don't include counts of NaN.

Returns

Series

Return a Series containing counts of unique values.

See Also

DataFrame.count

Number of non-NA elements in a DataFrame.

DataFrame.value_counts

Equivalent method on DataFrames.

Series.count

Number of non-NA elements in a Series.

Examples

This example is valid syntax, but we were not able to check execution
>>> index = pd.Index([3, 1, 2, 3, 4, np.nan])
... index.value_counts() 3.0 2 1.0 1 2.0 1 4.0 1 dtype: int64

With :None:None:`normalize` set to :None:None:`True`, returns the relative frequency by dividing all values by the sum of values.

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series([3, 1, 2, 3, 4, np.nan])
... s.value_counts(normalize=True) 3.0 0.4 1.0 0.2 2.0 0.2 4.0 0.2 dtype: float64

bins

Bins can be useful for going from a continuous variable to a categorical variable; instead of counting unique apparitions of values, divide the index in the specified number of half-open bins.

This example is valid syntax, but we were not able to check execution
>>> s.value_counts(bins=3)
(0.996, 2.0]    2
(2.0, 3.0]      2
(3.0, 4.0]      1
dtype: int64

dropna

With :None:None:`dropna` set to :None:None:`False` we can also see NaN index values.

This example is valid syntax, but we were not able to check execution
>>> s.value_counts(dropna=False)
3.0    2
1.0    1
2.0    1
4.0    1
NaN    1
dtype: int64
See :

Local connectivity graph

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


File: /pandas/core/base.py#884
type: <class 'function'>
Commit: