我有一个grouped类型的时间序列对象<pandas.core.groupby.SeriesGroupBy object at 0x03F1A9F0>.grouped.sum()给出了期望的结果,但我无法使用rolling_sum来处理groupby对象.有没有办法将滚动功能应用于groupby对象?例如:
x = range(0, 6)
id = ['a', 'a', 'a', 'b', 'b', 'b']
df = DataFrame(zip(id, x), columns = ['id', 'x'])
df.groupby('id').sum()
id x
a 3
b 12
Run Code Online (Sandbox Code Playgroud)
但是,我希望有类似的东西:
id x
0 a 0
1 a 1
2 a 3
3 b 3
4 b 7
5 b 12
Run Code Online (Sandbox Code Playgroud) python pandas rolling-computation rolling-sum pandas-groupby