Skip to content

Return the number of elements in each sub-list

Description

Null values are counted in the total.

Usage

<Expr>$list$len()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(list_of_strs = list(c("a", "b", NA), "c"))
df$with_columns(len_list = pl$col("list_of_strs")$list$len())
#> shape: (2, 2)
#> ┌──────────────────┬──────────┐
#> │ list_of_strs     ┆ len_list │
#> │ ---              ┆ ---      │
#> │ list[str]        ┆ u32      │
#> ╞══════════════════╪══════════╡
#> │ ["a", "b", null] ┆ 3        │
#> │ ["c"]            ┆ 1        │
#> └──────────────────┴──────────┘