title: Calculating mean and standard deviation in pandas dataframe
body: <p>I have the following dataframe:</p>
  <pre><code>    COD     CHM     DATE
  0   5713    0.0     2020-07-16
  1   5713    1.0     2020-08-11
  2   5713    2.0     2020-06-20
  3   5713    3.0     2020-06-19
  4   5713    4.0     2020-06-01
  ... ... ... ...
  2135283 73306036    0.0     2020-09-30
  2135284 73306055    12.0    2020-09-30
  2135285 73306479    9.0     2020-09-30
  2135286 73306656    3.0     2020-09-30
  2135287 73306676    1.0     2020-09-30
  </code></pre>
  <p>I want to calculate the mean and the standard deviation for each COD throughout the dates (time).
  For this, I am doing:</p>
  <pre><code>    traf_user_chm_med =traf_user_chm_med.groupby(['COD', 'DATE'])['CHM'].sum().reset_index()
  dates = pd.date_range(start=traf_user_chm_med.DATE.min(), end=traf_user_chm_med.DATE.max(), freq='MS', closed='left').sort_values(ascending=False)
  clients = traf_user_chm_med['COD'].unique()
  idx = pd.MultiIndex.from_product((clients, dates), names=['COD', 'DATE'])
  M0 = pd.to_datetime('2020-08')
  M1 = M0-pd.DateOffset(month=M0.month-1)
  M2 = M0-pd.DateOffset(month=M0.month-2)
  M3 = M0-pd.DateOffset(month=M0.month-3)
  M4 = M0-pd.DateOffset(month=M0.month-4)
  M5 = M0-pd.DateOffset(month=M0.month-5)
  def filter_dates(grp):
      grp.set_index('YEAR_MONTH', inplace=True)
      grp=grp[M0:M5].reset_index()
      return grp
  traf_user_chm_med = traf_user_chm_med.groupby('COD').apply(filter_dates)
  </code></pre>
  <p>Not sure why it doesn't work, it returns an empty dataframe.
  After this I would unstack to get the activity in the several months and calculate the mean and standard deviation for each COD.
  This is a long proccess, not sure if there is a faster way to do it that gets me the values I want.
  Still, if anyone can help me get this one working would be aweosome!</p>