pydata/pandas — pull request #7033 by TomAugspurger (2014-05-04 21:46:30+00:00)
Title: API: Allow groupby's by to take column and index names [WIP]

closes https://github.com/pydata/pandas/issues/5677

As a reminder, with a data frame like:

```python
from itertools import cycle, islice

np.random.seed(0)
df = pd.DataFrame(np.random.randn(20, 2))
df.columns = ["foo","bar"]
df['g0'] = list(islice(cycle('ab'), 20))
df['g1'] = ['a'] * 10 + ['b'] * 10
df['g2'] = ['c'] * 5 + ['d'] * 5 + ['c'] * 5 + ['d'] * 5

df = df.set_index(['g1', 'g2'])
```

Before if you wanted to groupby a a column and index level, you'd have to

```python
g = df.reset_index().groupby(['g0', 'g1'])
```

Now you can just do `df.groupby(['g0', 'g1'])`. In ambiguous cases where a there's a key in `by` that's in both the index names and columns we warn and proceed with grouping by the columns (I haven't tested this part yet).