monthly_sales['moving_avg_sales'] = monthly_sales.iloc[:,2].rolling(window=3).mean() monthly_sales['moving'] = monthly_sales.groupby('category')['actual_sales'].transform(lambda x: x.rolling(10, 1).mean()) monthly_sales['moving1'] = monthly_sales.groupby(['category', 'distributorid'])['actual_sales'].transform(lambda x: x.rolling(3).mean())
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter