title: Pandas: DataFrame groupby for year/month and return with new DatetimeIndex
body: <p>I need some directions in grouping a Pandas <code>DateFrame</code> object by year or month and get in return an new <code>DateFrame</code> object with a new index.
  Here is my code so far. <code>groupby</code> works as intended. </p>
  
  <p>Load data from .csv file, parse 'Date' to date format (historical stock quotes from finance.yahoo.com)</p>
  
  <pre><code>In [23]: import pandas as pd
           file = pd.read_csv("sdf.de.csv", parse_dates=['Date'])
           file.head(2)
  
  Out[23]:
      Date        Open    High    Low     Close   Volume  Adj Close
  0   2016-02-16  18.650  18.70   17.940  18.16   1720800 17.0600
  1   2016-02-15  18.295  18.64   18.065  18.50   1463500 17.3794
  </code></pre>
  
  <p>sort file for 'Date' ascending and set index to <code>Date</code></p>
  
  <pre><code>In [24]: daily = file.sort_values(by='Date').set_index('Date')
           daily.head()
  
  Out[24]:
              Open    High    Low     Close   Volume  Adj Close
  Date                        
  2000-01-03  14.20   14.50   14.15   14.40   277400  2.7916
  2000-01-04  14.29   14.30   13.90   14.15   109200  2.7431
  </code></pre>
  
  <p>grouping for month</p>
  
  <p>I would do an additional <code>apply()</code> to the groups, which would condense the data for the specific group, e.g. find the highest <code>High</code> value for the year/month or <code>sum()</code> the <code>Volume</code> values. This step is omitted for this example.</p>
  
  <pre><code>In [39]: monthly = daily.groupby(lambda x: (x.year, x.month))
           monthly.first()
  
  Out[39]:
              Open    High    Low     Close   Volume  Adj Close
  (2000, 1)   14.200  14.500  14.150  14.400  277400  2.7916
  (2000, 2)   13.900  14.390  13.900  14.250  287200  2.7625
  ... ... ... ... ... ... ...
  (2016, 1)   23.620  23.620  23.620  23.620  0       22.1893
  (2016, 2)   19.575  19.630  19.140  19.450  1783000 18.2719
  </code></pre>
  
  <p>This works, but it gives me a <code>DateFrame</code> object with a tuple as index.</p>
  
  <p>The desired result, in this case for grouping for month, would be a complete new <code>DataFrame</code> object, but the <code>Date</code> index should be a new <code>DatetimeIndex</code> in the form of <code>%Y-%m</code> or just <code>%Y</code> if grouped by year.</p>
  
  <pre><code>Out[39]:
          Open    High    Low     Close   Volume  Adj Close
  Date
  2000-01 14.200  14.500  14.150  14.400  277400  2.7916
  2000-02 13.900  14.390  13.900  14.250  287200  2.7625
  ... ... ... ... ... ... ...
  2016-01 23.620  23.620  23.620  23.620  0       22.1893
  2016-02 19.575  19.630  19.140  19.450  1783000 18.2719
  </code></pre>
  
  <p>I'm thankful for any directions. </p>