modin.pandas.Index.value_counts

Index.value_counts(normalize: bool = False, sort: bool = True, ascending: bool = False, bins: int | None = None, dropna: bool = True) Series[source]

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.

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 when True. Preserve the order of the data when False.

  • 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. bins is not yet supported.

  • dropna (bool, default True) – Don’t include counts of NaN.

Returns:

A Series containing counts of unique values.

Return type:

Series

See also

Series.count

Number of non-NA elements in a Series.

DataFrame.count

Number of non-NA elements in a DataFrame.

DataFrame.value_counts

Equivalent method on DataFrames.

Examples

>>> 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
Name: count, dtype: int64
Copy

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

>>> ind = pd.Index([3, 1, 2, 3, 4, np.nan])
>>> ind.value_counts(normalize=True)
3.0    0.4
1.0    0.2
2.0    0.2
4.0    0.2
Name: proportion, dtype: float64
Copy

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.