polars.Series.value_counts#

Series.value_counts(sort: bool = False) DataFrame[source]#

Count the unique values in a Series.

Parameters:
sort

Ensure the output is sorted from most values to least.

Examples

>>> s = pl.Series("a", [1, 2, 2, 3])
>>> s.value_counts().sort(by="a")
shape: (3, 2)
┌─────┬────────┐
│ a   ┆ counts │
│ --- ┆ ---    │
│ i64 ┆ u32    │
╞═════╪════════╡
│ 1   ┆ 1      │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2   ┆ 2      │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 3   ┆ 1      │
└─────┴────────┘