在滚动滚动大熊猫时,索引被添加两次。错误吗?
test = DF({"a": range(10), "b": range(10)[::-1]}, index = pd.Index(np.tile([0,1], 5), name="id"))
test.sort_index(inplace = True)
test.groupby("id").rolling(window = 2).sum()
a b
id id
0 0 NaN NaN
0 2.0 16.0
0 6.0 12.0
0 10.0 8.0
0 14.0 4.0
1 1 NaN NaN
1 4.0 14.0
1 8.0 10.0
1 12.0 6.0
1 16.0 2.0
将group_keys
设置为False
(工作)是正确的解决方法,尽管我认为这仅适用于apply
?