Skip to content

Get the number of unique values in a list

Source code

Description

Get the number of unique values in a list

Usage

<Expr>$list$n_unique()

Value

Expr

Examples

library("polars")

df = pl$DataFrame(values = list(c(2, 2, NA), c(1, 2, 3), NA_real_))
df$with_columns(unique = pl$col("values")$list$n_unique())
#> shape: (3, 2)
#> ┌──────────────────┬────────┐
#> │ values           ┆ unique │
#> │ ---              ┆ ---    │
#> │ list[f64]        ┆ u32    │
#> ╞══════════════════╪════════╡
#> │ [2.0, 2.0, null] ┆ 2      │
#> │ [1.0, 2.0, 3.0]  ┆ 3      │
#> │ [null]           ┆ 1      │
#> └──────────────────┴────────┘