Skip to content

Count unique values in the order of appearance

Description

This method differs from $value_counts() in that it does not return the values, only the counts and might be faster.

Usage

<Expr>$unique_counts()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(id = c("a", "b", "b", "c", "c", "c"))
df$select(pl$col("id")$unique_counts())
#> shape: (3, 1)
#> ┌─────┐
#> │ id  │
#> │ --- │
#> │ u32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> └─────┘