Skip to content

Add a suffix to all fields name of a struct

Source code

Description

Add a suffix to all fields name of a struct

Usage

<Expr>$name$suffix_fields(suffix)

Arguments

suffix Suffix to add to the field name.

Value

Expr

Examples

library("polars")

df = pl$DataFrame(a = 1, b = 2)$select(
  pl$struct(pl$all())$alias("my_struct")
)

df$with_columns(pl$col("my_struct")$name$suffix_fields("_post"))$unnest()
#> shape: (1, 2)
#> ┌────────┬────────┐
#> │ a_post ┆ b_post │
#> │ ---    ┆ ---    │
#> │ f64    ┆ f64    │
#> ╞════════╪════════╡
#> │ 1.0    ┆ 2.0    │
#> └────────┴────────┘