Polars 2 · Expressions, grouping and joins

Pivot a DataFrame

Turn values of one column into columns.

long = pl.DataFrame({"team": ["a", "a", "b"], "kind": ["x", "y", "x"], "n": [1, 2, 3]})
long.pivot(on="kind", index="team", values="n")

Official Polars 2 documentation

More expressions, grouping and joins commands

All expressions, grouping and joins commands · Polars 2 cheatsheet

Was this page helpful?