polars.Expr.name.map_fields#

Expr.name.map_fields(function: Callable[[str], str]) Expr[source]#

Rename fields of a struct by mapping a function over the field name(s).

Parameters:
function

Function that maps a field name to a new name.

Notes

This only takes effect for struct columns.

Examples

>>> df = pl.DataFrame({"x": {"a": 1, "b": 2}})
>>> df.select(pl.col("x").name.map_fields(lambda x: x.upper())).schema
Schema({'x': Struct({'A': Int64, 'B': Int64})})