Skip to content

field

Source code

Description

Retrieve a Struct field as a new Series. By default base 2.

Usage

<Expr>$struct$field(name)

Arguments

name string, the Name of the struct field to retrieve.

Value

Expr: Series of same and name selected field.

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]      │
#> └─────┴────────────┘