Pandas groupby ewm Pandas groupby ewm pandas pandas

Pandas groupby ewm


Let's fix the problem, using transform:

t['ewm'] = ts.groupby(['C1'])['X1'].transform(lambda x: x.ewm(halflife=10).mean()).values()


Can you try this?Do NOT set ts = df.set_index('T'). Then you can do as below

ts['ewm']=ts.groupby(['C1'], sort=False).apply(lambda x: x['X1'].ewm(halflife=10).mean()).reset_index(drop=True)