pydata/pandas — pull request #6516 by jreback (2014-03-01 22:37:45+00:00)
Title: BUG/API: allow TimeGrouper with other columns in a groupby (GH3794)

closes #3794

allows the integration of a TimeGrouper and a regular grouper in a groupby expression,

```
In [3]: df
Out[3]:
Branch Buyer Quantity
Date
2013-10-01 13:00:00 A Carl 1
2013-10-01 13:05:00 A Mark 3
2013-10-01 20:00:00 A Carl 5
2013-10-02 10:00:00 A Carl 1
2013-10-01 20:00:00 A Joe 8
2013-10-02 10:00:00 A Joe 1
2013-10-02 12:00:00 A Joe 9
2013-10-02 14:00:00 B Carl 3

[8 rows x 3 columns]

In [4]: df.groupby([pd.TimeGrouper('1D'),'Buyer']).sum()
Out[4]:
Quantity
Date Buyer
2013-10-01 Carl 6
Joe 8
Mark 3
2013-10-02 Carl 4
Joe 10

[5 rows x 1 columns]

In [5]: df.groupby([pd.TimeGrouper('1M'),'Buyer']).sum()
Out[5]:
Quantity
Date Buyer
2013-10-31 Carl 10
Joe 18
Mark 3

[3 rows x 1 columns]
```

Note that I added name/level to TimeGrouper to provide a specification of what this is referring to, e.g. a column (name) or a level of the index (level).
```
In [6]: df.reset_index().groupby([pd.TimeGrouper('1M',name='Date'),'Buyer']).sum()
Out[6]:
Quantity
Date Buyer
2013-10-31 Carl 10
Joe 18
Mark 3

[3 rows x 1 columns]
```