polars.Expr.over

Expr.over(expr: Union[str, polars.internals.expr.Expr, List[Union[polars.internals.expr.Expr, str]]]) polars.internals.expr.Expr

Apply window function over a subgroup. This is similar to a groupby + aggregation + self join. Or similar to [window functions in Postgres](https://www.postgresql.org/docs/9.1/tutorial-window.html)

Parameters
expr

Column(s) to group by.

Examples

>>> df = pl.DataFrame(
...     {
...         "groups": [1, 1, 2, 2, 1, 2, 3, 3, 1],
...         "values": [1, 2, 3, 4, 5, 6, 7, 8, 8],
...     }
... )
>>> (
...     df.lazy()
...     .select(
...         [
...             pl.col("groups").sum().over("groups"),
...         ]
...     )
...     .collect()
... )
shape: (9, 1)
┌────────┐
│ groups │
│ ---    │
│ i64    │
╞════════╡
│ 4      │
├╌╌╌╌╌╌╌╌┤
│ 4      │
├╌╌╌╌╌╌╌╌┤
│ 6      │
├╌╌╌╌╌╌╌╌┤
│ 6      │
├╌╌╌╌╌╌╌╌┤
│ ...    │
├╌╌╌╌╌╌╌╌┤
│ 6      │
├╌╌╌╌╌╌╌╌┤
│ 6      │
├╌╌╌╌╌╌╌╌┤
│ 6      │
├╌╌╌╌╌╌╌╌┤
│ 4      │
└────────┘