Skip to content

Get the length of each list

Source code

Description

Return the number of elements in each list. Null values are counted in the total.

Usage

<Expr>$list$len()

Value

Expr

Examples

library("polars")

df = pl$DataFrame(list(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        │
#> └──────────────────┴──────────┘