pydata/pandas — pull request #6913 by sinhrks (2014-04-19 17:12:53+00:00)
Title: ENH: pivot_table can now accept Grouper

`pivot_table` can accept `Grouper` by `index` and `columns` kw.

```
>>> df = pd.DataFrame({
'Branch' : 'A A A A A A A B'.split(),
'Buyer': 'Carl Mark Carl Carl Joe Joe Joe Carl'.split(),
'Quantity': [1,3,5,1,8,1,9,3],
'Date' : [datetime(2013,11,1,13,0), datetime(2013,9,1,13,5),
datetime(2013,10,1,20,0), datetime(2013,10,2,10,0),
datetime(2013,11,1,20,0), datetime(2013,10,2,10,0),
datetime(2013,10,2,12,0), datetime(2013,12,5,14,0)],
'PayDay' : [datetime(2013,10,4,0,0), datetime(2013,10,15,13,5),
datetime(2013,9,5,20,0), datetime(2013,11,2,10,0),
datetime(2013,10,7,20,0), datetime(2013,9,5,10,0),
datetime(2013,12,30,12,0), datetime(2013,11,20,14,0),]})

>>> pd.pivot_table(df, index=pd.Grouper(freq='M', key='Date'),
columns=pd.Grouper(freq='M', key='PayDay'),
values='Quantity', aggfunc=np.sum)
PayDay 2013-09-30 2013-10-31 2013-11-30 2013-12-31
Date
2013-09-30 NaN 3 NaN NaN
2013-10-31 6 NaN 1 9
2013-11-30 NaN 9 NaN NaN
2013-12-31 NaN NaN 3 NaN
```