Skip to content

Explode a list or String Series

Source code

Description

This means that every item is expanded to a new row.

Usage

<Expr>$explode()

Details

Categorical values are not supported.

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")$explode())
#> shape: (6, 1)
#> ┌─────┐
#> │ y   │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> │ 3   │
#> │ 4   │
#> │ 5   │
#> └─────┘