Skip to content

Instantly share code, notes, and snippets.

@dormeir999
Last active August 13, 2022 06:58
Show Gist options
  • Select an option

  • Save dormeir999/e28447196f446c4154b0fc8ade002aa9 to your computer and use it in GitHub Desktop.

Select an option

Save dormeir999/e28447196f446c4154b0fc8ade002aa9 to your computer and use it in GitHub Desktop.
assert df.isna().sum().sum() == 0
total_sales_5_days_rolling_window = df.groupby(['product','date']).sales.sum().rolling(5, min_periods=0).agg(['min','max','mean','sum']).add_prefix('country_sales_rolling_5_')
df = df.merge(total_sales_5_days_rolling_window, on=['product','date'], how='left')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment