import polars as pl
df = pl.DataFrame(
{
"foo": ["A", "A", "B", "B", "C"],
"N": [1, 2, 2, 4, 2],
"bar": ["k", "l", "m", "n", "o"],
}
)
print(df)
out = df.pivot("bar", index="foo", values="N", aggregate_function="first")
print(out)
q = (
df.lazy()
.collect()
.pivot(index="foo", on="bar", values="N", aggregate_function="first")
.lazy()
)
out = q.collect()
print(out)