polars.n_unique#

polars.n_unique(column: str) Expr[source]#
polars.n_unique(column: Series) int

Count unique values.

Examples

>>> df = pl.DataFrame({"a": [1, 8, 1], "b": [4, 5, 2], "c": ["foo", "bar", "foo"]})
>>> df.select(pl.n_unique("a"))
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ u32 │
╞═════╡
│ 2   │
└─────┘