Method: Polars::StructExpr#rename_fields

Defined in:
lib/polars/struct_expr.rb

#rename_fields(names) ⇒ Expr

Rename the fields of the struct.

Examples:

df = (
  Polars::DataFrame.new(
    {
      "int" => [1, 2],
      "str" => ["a", "b"],
      "bool" => [true, nil],
      "list" => [[1, 2], [3]]
    }
  )
  .to_struct("my_struct")
  .to_frame
)
df = df.with_columns(
  Polars.col("my_struct").struct.rename_fields(["INT", "STR", "BOOL", "LIST"])
)
df.select(Polars.col("my_struct").struct.field("INT"))
# =>
# shape: (2, 1)
# ┌─────┐
# │ INT │
# │ --- │
# │ i64 │
# ╞═════╡
# │ 1   │
# │ 2   │
# └─────┘

Parameters:

  • names (Array)

    New names in the order of the struct's fields

Returns:



142
143
144
# File 'lib/polars/struct_expr.rb', line 142

def rename_fields(names)
  Utils.wrap_expr(_rbexpr.struct_rename_fields(names))
end