title: Keep a column with a categorical variable in Pandas with groupby and mean()
body: <p>Is there a way to keep the categorical variable after <code>groupby</code> and <code>mean()</code>?
  For example, given the dataframe <code>df</code>:</p>
  
  <pre><code>              ratio    Metadata_A      Metadata_B   treatment
  0      54265.937500           B10               1  AB_cmpd_01
  11    107364.750000           B10               2  AB_cmpd_01
  22     95766.500000           B10               3  AB_cmpd_01
  24     64346.250000           B10               4  AB_cmpd_01
  25     52726.333333           B10               5  AB_cmpd_01
  30     65056.600000           B11               1          UT
  41     78409.600000           B11               2          UT
  52    133533.000000           B11               3          UT
  54    102433.571429           B11               4          UT
  55     82217.588235           B11               5          UT
  60     89843.600000            B2               1          UT
  71     98544.000000            B2               2          UT
  82    179330.000000            B2               3          UT
  84    107132.400000            B2               4          UT
  85     73096.909091            B2               5          UT
  </code></pre>
  
  <p>I need to average over <code>ratio</code> within each of <code>Metadata_A</code>, but at the end to keep the column <code>treatment</code>:</p>
  
  <p>Theoretically, something like: </p>
  
  <pre><code>df.groupby(by='Metadata_A').mean().reset_index()
  
                ratio    Metadata_A      Metadata_B   treatment
   0     54265.937500           B10             2.5  AB_cmpd_01
   1     78409.600000           B11             2.5          UT
   2    107132.400000            B2             2.5          UT
  </code></pre>
  
  <p>However, the column <code>treatment</code> disappears after the averaging.</p>