问题:对于RollingGroupby对象,.agg方法是否有效?看起来它应该和IPython自动填充这个方法,但是我得到了一个错误。在
文档:我没有看到任何特定于RollingGroupby对象的内容。我可能找错地方了,但我看了Standard moving window functions和{a2}
样本数据:# test data
df = pd.DataFrame({
'animal':np.random.choice( ['panda','python','shark'], 12),
'period':np.repeat(range(3), 4 ),
'value':np.tile(range(2), 6 ),
})
# this works as expected
df.groupby(['animal', 'period'])['value'].rolling(2).count()
animal period
panda 0 2 1.0
2 8 1.0
10 2.0
python 0 0 1.0
1 2.0
1 6 1.0
2 11 1.0
shark 0 3 1.0
1 4 1.0
5 2.0
7 2.0
2 9 1.0
Name: value, dtype: float64
# this works as expected
df.groupby(['animal'