Skip to content

Convert a List column into an Array column with the same inner data type

Description

Convert a List column into an Array column with the same inner data type

Usage

<Expr>$list$to_array(width)

Arguments

width Width of the resulting Array column.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(values = list(c(-1, 0), c(1, 10)))

df$with_columns(
  array = pl$col("values")$list$to_array(2)
)
#> shape: (2, 2)
#> ┌─────────────┬───────────────┐
#> │ values      ┆ array         │
#> │ ---         ┆ ---           │
#> │ list[f64]   ┆ array[f64, 2] │
#> ╞═════════════╪═══════════════╡
#> │ [-1.0, 0.0] ┆ [-1.0, 0.0]   │
#> │ [1.0, 10.0] ┆ [1.0, 10.0]   │
#> └─────────────┴───────────────┘