polars.internals.expr.struct.ExprStructNameSpace.rename_fields#

ExprStructNameSpace.rename_fields(names: list[str]) Expr[source]#

Rename the fields of the struct.

Parameters:
names

New names in the order of the struct’s fields

Examples

>>> df = (
...     pl.DataFrame(
...         {
...             "int": [1, 2],
...             "str": ["a", "b"],
...             "bool": [True, None],
...             "list": [[1, 2], [3]],
...         }
...     )
...     .to_struct("my_struct")
...     .to_frame()
... )
>>> df = df.with_column(
...     pl.col("my_struct").struct.rename_fields(["INT", "STR", "BOOL", "LIST"])
... )

Does NOT work anymore: # df.select(pl.col(“my_struct”).struct.field(“int”)) # PanicException: int not found ^^^

>>> df.select(pl.col("my_struct").struct.field("INT"))
shape: (2, 1)
┌─────┐
│ INT │
│ --- │
│ i64 │
╞═════╡
│ 1   │
├╌╌╌╌╌┤
│ 2   │
└─────┘