Skip to content

Explode a list or String Series

Source code

Description

This is an alias for <Expr>$explode().

Usage

<Expr>$flatten()

Value

Expr

Examples

library("polars")

df = pl$DataFrame(x = c("abc", "ab"), y = c(list(1:3), list(3:5)))
df
#> shape: (2, 2)
#> ┌─────┬───────────┐
#> │ x   ┆ y         │
#> │ --- ┆ ---       │
#> │ str ┆ list[i32] │
#> ╞═════╪═══════════╡
#> │ abc ┆ [1, 2, 3] │
#> │ ab  ┆ [3, 4, 5] │
#> └─────┴───────────┘
df$select(pl$col("y")$flatten())
#> shape: (6, 1)
#> ┌─────┐
#> │ y   │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> │ 3   │
#> │ 4   │
#> │ 5   │
#> └─────┘