Skip to content

Explode the frame to long format by exploding the given columns

Description

Explode the frame to long format by exploding the given columns

Usage

<DataFrame>$explode(...)

Arguments

\<dynamic-dots\> Column names, expressions, or a selector defining them. The underlying columns being exploded must be of the List or Array data type.

Value

A polars DataFrame

Examples

library("polars")

df <- pl$DataFrame(
  letters = c("a", "a", "b", "c"),
  numbers = list(1, c(2, 3), c(4, 5), c(6, 7, 8))
)

df$explode("numbers")
#> shape: (8, 2)
#> ┌─────────┬─────────┐
#> │ letters ┆ numbers │
#> │ ---     ┆ ---     │
#> │ str     ┆ f64     │
#> ╞═════════╪═════════╡
#> │ a       ┆ 1.0     │
#> │ a       ┆ 2.0     │
#> │ a       ┆ 3.0     │
#> │ b       ┆ 4.0     │
#> │ b       ┆ 5.0     │
#> │ c       ┆ 6.0     │
#> │ c       ┆ 7.0     │
#> │ c       ┆ 8.0     │
#> └─────────┴─────────┘