Polars: group_by rolling sum
12:41 02 Jan 2023

Say I have

df = pl.DataFrame({'group': [1, 1, 1, 3, 3, 3, 4, 4], 'value': [1, 4, 2, 5, 3, 4, 2, 3]})

I'd like to get a rolling sum, with window of 2, for each group

Expected output is:

┌───────┐
│ value │
│ ---   │
│ i64   │
╞═══════╡
│ 1     │
│ 5     │
│ 6     │
│ 5     │
│ 8     │
│ 7     │
│ 2     │
│ 5     │
└───────┘
python dataframe window-functions python-polars rolling-computation