Skip to content

Retrieve one of the fields of this Struct as a new Series

Source code

Description

Retrieve one of the fields of this Struct as a new Series

Usage

<Expr>$struct$field(name)

Arguments

name Name of the field.

Value

Expr of datatype Struct

Examples

library("polars")

df = pl$DataFrame(
  aaa = c(1, 2),
  bbb = c("ab", "cd"),
  ccc = c(TRUE, NA),
  ddd = list(c(1, 2), 3)
)$select(
  pl$struct(pl$all())$alias("struct_col")
)
# struct field into a new Series
df$select(
  pl$col("struct_col")$struct$field("bbb"),
  pl$col("struct_col")$struct$field("ddd")
)
#> shape: (2, 2)
#> ┌─────┬────────────┐
#> │ bbb ┆ ddd        │
#> │ --- ┆ ---        │
#> │ str ┆ list[f64]  │
#> ╞═════╪════════════╡
#> │ ab  ┆ [1.0, 2.0] │
#> │ cd  ┆ [3.0]      │
#> └─────┴────────────┘