pandas.Series.value_counts

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. Excludes NA values by default.

param normalize
boolean, default False

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

param sort
boolean, default True

Sort by frequencies.

param ascending
boolean, default False

Sort in ascending order.

param bins
integer, optional

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

param dropna
boolean, default True

Don’t include counts of NaN.

return

Series

Limitations

  • Parameters normalize and bins are currently unsupported.

  • Parameter dropna is unsupported for String Series.

  • Elements with the same count might appear in result in a different order than in Pandas.

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff

    between staying in JIT-region with that function or going back to interpreter mode.

Examples

Getting the number of values excluding NaNs
import pandas as pd
import numpy as np
from numba import njit


@njit
def series_value_counts():
    s = pd.Series([3, 1, 2, 3, 4, np.nan])
    out_series = s.value_counts()

    return out_series


print(series_value_counts())
$ python ./series/series_value_counts.py
3.0    2
4.0    1
2.0    1
1.0    1
dtype: int64

See also

Series.count