Closed
Description
Hello everyone, updating to Pandas 0.15.1 breaks my code because of the following behaviour. When performing an aggregation operation on a groupby object containing a categorical, with as_index=False, this column is now dropped from the aggregation result. This may be an unexpected consequence of #8585 , and certainly looks as a bug to me.
import pandas as pd
import numpy as np
d = {'Foo': [1, 2, 3, 4, 5, 6, 11],
'Bar': ['AA', 'AA', 'AA', 'BB', 'BB', 'BB',
'CC'],
'Baz': [10, 20, 30, 40, 50, 60, 70]}
df = pd.DataFrame(d)
ls = np.linspace(0, 30, 7)
groups = df.groupby([pd.cut(df['Foo'], ls), 'Bar'], as_index=False)
df2 = groups['Baz'].agg({'Mean Baz': 'mean'})
produces:
>>> pd.__version__
'0.15.1'
>>> df2
Bar | Mean Baz | |
---|---|---|
0 | AA | 20 |
1 | BB | 45 |
2 | BB | 60 |
3 | CC | 70 |
, whereas I expect the following:
>>> pd.__version__
'0.15.0'
Foo | Bar | Mean Baz | |
---|---|---|---|
0 | (0, 5] | AA | 20 |
1 | (0, 5] | BB | 45 |
2 | (5, 10] | BB | 60 |
3 | (10, 15] | CC | 70 |