title: Speed up rolling window in Pandas
body: <p>I have this code which works fine and gives me the result I am looking for. It loops through a list of window sizes to create rolling aggregates for each metric in the sum_metric_list, min_metric_list and max_metric_list.</p>
  
  <pre><code># create the rolling aggregations for each window
  for window in constants.AGGREGATION_WINDOW:
      # get the sum and count sums
      sum_metrics_names_list = [x[6:] + "_1_" + str(window) for x in sum_metrics_list]
      adt_df[sum_metrics_names_list] = adt_df.groupby('athlete_id')[sum_metrics_list].apply(lambda x : x.rolling(center = False, window = window, min_periods = 1).sum())
  
      # get the min of mins
      min_metrics_names_list = [x[6:] + "_1_" + str(window) for x in min_metrics_list]
      adt_df[min_metrics_names_list] = adt_df.groupby('athlete_id')[min_metrics_list].apply(lambda x : x.rolling(center = False, window = window, min_periods = 1).min())
  
      # get the max of max
      max_metrics_names_list = [x[6:] + "_1_" + str(window) for x in max_metrics_list]
      adt_df[max_metrics_names_list] = adt_df.groupby('athlete_id')[max_metrics_list].apply(lambda x : x.rolling(center = False, window = window, min_periods = 1).max())
  </code></pre>
  
  <p>It works well on small datasets but as soon as I run it on my full data with >3000 metrics and 40 windows it becomes very slow. Is there any way to optimise this code?</p>