title: resample a pandas df within each group
body: <p>I have a df that has a <code>MultiIndex</code> of <code>(id, date)</code> and I would like to do 2 things:</p>
  
  <ol>
  <li><p>convert the <code>DateTimeIndex</code> named <code>date</code> to a <code>PeriodIndex</code> within each <code>id</code> group</p></li>
  <li><p><code>resample</code> the frequency of the <code>PeriodIndex</code> to monthly from daily</p></li>
  </ol>
  
  <p>My current (non-working) method is to (even before converting to <code>PeriodIndex</code>):</p>
  
  <pre><code>df = pd.DataFrame(data = {"val": np.arange(30), 
                            "id": np.tile([1,2], 15),
                            "date": np.repeat(pd.date_range(start = "2000-01-01", periods = 15, name="date"), 2)
                           })
  
  df = df.set_index(["id", "date"]).sort_index() 
  df.groupby("id")["val"].resample(rule = "M", closed = "right", label = "right").apply(lambda x: np.sqrt(sum(x)/10))
  </code></pre>
  
  <p>This raises:</p>
  
  <pre><code>TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'MultiIndex'
  </code></pre>
  
  <p>What's the right way to do the whole procedure? I'm a bit confused about how to think about <code>groupby</code>: my mental model is that anything that follows a <code>groupby</code> operation will only receive the subframe corresponding to that group (ie the <code>MultiIndex</code> becomes a single index of just <code>date</code> within that particular group). Is this not correct?</p>