BUG: Grouper(key='A') gives AttributeError when applying function · Issue #8795 · pandas-dev/pandas (original) (raw)
I was playing a bit with pd.Grouper
. Shouldn't the following work:
In [109]: df = pd.DataFrame({'A':[0,0,1,1,2,2], 'B':[1,2,3,4,5,6]})
In [110]: df
Out[110]:
A B
0 0 1
1 0 2
2 1 3
3 1 4
4 2 5
5 2 6
In [111]: df.groupby(pd.Grouper(key='A')).sum()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-111-b9e051aabea3> in <module>()
----> 1 df.groupby(pd.Grouper(key='A')).sum()
C:\Anaconda\lib\site-packages\pandas\core\groupby.pyc in f(self)
108 raise SpecificationError(str(e))
109 except Exception:
--> 110 result = self.aggregate(lambda x: npfunc(x, axis=self.axis))
111 if _convert:
112 result = result.convert_objects()
C:\Anaconda\lib\site-packages\pandas\core\groupby.pyc in aggregate(self, arg, *a
rgs, **kwargs)
2634 return getattr(self, cyfunc)()
2635
-> 2636 if self.grouper.nkeys > 1:
2637 return self._python_agg_general(arg, *args, **kwargs)
2638 else:
AttributeError: 'Int64Index' object has no attribute 'nkeys'