polars.internals.expr.ExprStructNameSpace.rename_fields

ExprStructNameSpace.rename_fields(names: List[str]) polars.internals.expr.Expr

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