title: pandas groupby dates within a quarter
body: <p>I have two companies with different year-ends (1/31 and 12/31) and I want to get the average for metrics that occur in their respective quarters. For this example, I've created a DataFrame with the 8 quarter-end dates for 2016-2017 for both companies:</p>
  
  <pre><code>comp1 = pd.date_range('1/31/2016', periods=8, freq='3M')
  comp2 = pd.date_range('1/31/2016', periods=8, freq='Q')
  quarters = pd.DataFrame([1] * 8 + [2] * 8, index=comp1.append(comp2), columns=['company'])
  </code></pre>
  
  <p>Here's made up data, where I have two values (A and B) that are measured at random dates within each month for the years 2016 and 2017:</p>
  
  <pre><code>values = np.transpose([np.arange(1, 25), np.arange(1, 25) *  11])
  dates = ['2016-01-14', '2016-02-03', '2016-03-15', '2016-04-04', 
           '2016-05-30', '2016-06-11', '2016-07-18', '2016-08-08', 
           '2016-09-09', '2016-10-10', '2016-11-01', '2016-12-24', 
           '2017-01-30', '2017-02-19', '2017-03-13', '2017-04-24', 
           '2017-05-31', '2017-06-02', '2017-07-28', '2017-08-23', 
           '2017-09-04', '2017-10-30', '2017-11-11', '2017-12-06']
  df = pd.DataFrame(values, index=pd.DatetimeIndex(dates), columns=['A', 'B'])
  </code></pre>
  
  <p>The data looks like this:</p>
  
  <pre><code>             A    B
  2016-01-14   1   11
  2016-02-03   2   22
  2016-03-15   3   33
  2016-04-04   4   44
  2016-05-30   5   55
  2016-06-11   6   66
  2016-07-18   7   77
  2016-08-08   8   88
  2016-09-09   9   99
  2016-10-10  10  110
  2016-11-01  11  121
  2016-12-24  12  132
  2017-01-30  13  143
  2017-02-19  14  154
  2017-03-13  15  165
  2017-04-24  16  176
  2017-05-31  17  187
  2017-06-02  18  198
  2017-07-28  19  209
  2017-08-23  20  220
  2017-09-04  21  231
  2017-10-30  22  242
  2017-11-11  23  253
  2017-12-06  24  264
  </code></pre>
  
  <p>Here's the result I want, grouping by the quarters and averaging the values within each quarter:</p>
  
  <pre><code>            company   A    B
  2016-01-31        1   1   11
  2016-04-30        1   3   33
  2016-07-31        1   6   66
  2016-10-31        1   9   99
  2017-01-31        1  12  132
  2017-04-30        1  15  165
  2017-07-31        1  18  198
  2017-10-31        1  21  231
  2016-03-31        2   2   22
  2016-06-30        2   5   55
  2016-09-30        2   8   88
  2016-12-31        2  11  121
  2017-03-31        2  14  154
  2017-06-30        2  17  187
  2017-09-30        2  20  220
  2017-12-31        2  23  253
  </code></pre>