polars.Expr.unique_counts#
- Expr.unique_counts() Expr [source]#
Return a count of the unique values in the order of appearance.
This method differs from
value_counts
in that it does not return the values, only the counts and might be fasterExamples
>>> df = pl.DataFrame( ... { ... "id": ["a", "b", "b", "c", "c", "c"], ... } ... ) >>> df.select( ... [ ... pl.col("id").unique_counts(), ... ] ... ) shape: (3, 1) ┌─────┐ │ id │ │ --- │ │ u32 │ ╞═════╡ │ 1 │ │ 2 │ │ 3 │ └─────┘