title: How to do a 'groupby' by multilevel index in Pandas
body: <p>I have a dataframe 'RPT' indexed by (STK_ID,RPT_Date), contains the accumulated sales of stocks for each qurter:</p>
  
  <pre><code>                       sales
  STK_ID  RPT_Date
  000876  20060331      798627000
          20060630     1656110000
          20060930     2719700000
          20061231     3573660000
          20070331      878415000
          20070630     2024660000
          20070930     3352630000
          20071231     4791770000
  600141  20060331      270912000
          20060630      658981000
          20060930     1010270000
          20061231     1591500000
          20070331      319602000
          20070630      790670000
          20070930     1250530000
          20071231     1711240000
  </code></pre>
  
  <p>I want to calculate the single qurterly sales using 'groupby' by STK_ID &amp; RPT_Yr ,such as : <code>RPT.groupby('STK_ID','RPT_Yr')['sales'].transform(lambda x: x-x.shift(1))</code> , how to do that ?</p>
  
  <p>suppose I can get the year by <code>lambda x : datetime.strptime(x, '%Y%m%d').year</code>  </p>