title: Python Pandas - Carrying the index over as the group name/index for a groupby produced dataframe
body: <p>I have used groupby in pandas, however the label for the groups is simply an arbitrary value, whereas I would like this label to be the index of the original dataframe (which is datetime) so that I can create a new dataframe which I can plot in terms of datetime. </p>
  
  <pre><code>    grouped_data = df.groupby(
              ['X',df.X.ne(df.X.shift()).cumsum().rename('grp')])
  
      grouped_data2 = grouped_data['Y'].agg(np.trapz).loc[2.0:4.0]
  </code></pre>
  
  <p>The column x has changing values from 1-4 and the second line of code is intended to integrate the column Y in the groups where X is either 2 or 3. These are repeating units, so I don't want all the 2s and all the 3s integrated together, I want the period of time where it goes: <code>22222333333</code> as one group and then apply the np.trapz again to the next group where it goes: <code>2222233333</code>. That way I should have a new dataframe with an index corresponding to the start of these time periods and values which are an integral of these periods. </p>