I'm trying to find faster alternative for the following code using polars
df['ewm'] = df.groupby(['outlet', 'product'])['sales'].transform(lambda x: x.shift(shift).ewm(com=10).mean())
Please find MWE example below
df = pd.DataFrame({"outlet": [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
"product": [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3],
"sales": [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]})
outlet product sales ewm
0 1 1 1 NaN
1 1 1 2 1.00
2 1 1 3 1.52
3 1 2 4 NaN
4 1 2 5 4.00
5 1 2 6 4.52
6 1 3 7 NaN
7 1 3 8 7.00
8 1 3 9 7.52
....