title: get first and last values in a groupby
body: <p>I have a dataframe <code>df</code></p>
  
  <pre><code>df = pd.DataFrame(np.arange(20).reshape(10, -1),
                    [['a', 'a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd'],
                     ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']],
                    ['X', 'Y'])
  </code></pre>
  
  <p>How do I get the first and last rows, grouped by the first level of the index?</p>
  
  <p>I tried</p>
  
  <pre><code>df.groupby(level=0).agg(['first', 'last']).stack()
  </code></pre>
  
  <p>and got</p>
  
  <pre><code>          X   Y
  a first   0   1
    last    6   7
  b first   8   9
    last   12  13
  c first  14  15
    last   16  17
  d first  18  19
    last   18  19
  </code></pre>
  
  <p>This is so close to what I want.  How can I preserve the level 1 index and get this instead:</p>
  
  <pre><code>      X   Y
  a a   0   1
    d   6   7
  b e   8   9
    g  12  13
  c h  14  15
    i  16  17
  d j  18  19
    j  18  19
  </code></pre>