Skip to content

polars/polars-groupby-join-over

Pack Severity Fix Versions
Polars info none, edit by hand All versions

A join to an aggregation of the same Polars frame can often be written as a window expression. Check the output names and how null keys should be grouped.

df.join(df.group_by("y").agg(total=expr.sum()), on="y")
df.with_columns(total=expr.sum().over("y"))

Three rows with non-null keys gave equal frames.

Edit the code using the replacement in the example.

A join to an aggregation of the same Polars frame can often be written as a window expression. Check the output names and how null keys should be grouped.

See all rules in the Polars pack.