I use the following code to calculate the moving average excluding current row by groups. However, I would like to change it to weighted moving average. Is there any way to improve this code to calculate weighted moving average?
df_ssALL['wma'] = df.sort_values(by=['date']).groupby('Name')['value'].apply(lambda x: x.rolling(4, 1).mean().shift().bfill())
2.1m questions
2.1m answers
60 comments
57.0k users