Skip to content

Get the first value in a list

Source code

Description

Get the first value in a list

Usage

<Expr>$list$first()

Value

Expr

Examples

library("polars")

df = pl$DataFrame(list(a = list(3:1, NULL, 1:2)))
df$with_columns(
  first = pl$col("a")$list$first()
)
#> shape: (3, 2)
#> ┌───────────┬───────┐
#> │ a         ┆ first │
#> │ ---       ┆ ---   │
#> │ list[i32] ┆ i32   │
#> ╞═══════════╪═══════╡
#> │ [3, 2, 1] ┆ 3     │
#> │ []        ┆ null  │
#> │ [1, 2]    ┆ 1     │
#> └───────────┴───────┘