rolling-sum

Python - rolling functions for GroupBy object

邮差的信 提交于 2019-11-28 18:12:32
I have a time series object grouped of the type <pandas.core.groupby.SeriesGroupBy object at 0x03F1A9F0> . grouped.sum() gives the desired result but I cannot get rolling_sum to work with the groupby object. Is there any way to apply rolling functions to groupby objects? For example: 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 However, I would like to have something like: id x 0 a 0 1 a 1 2 a 3 3 b 3 4 b 7 5 b 12 Note: as identified by @kekert, the following pandas pattern has been deprecated. See

Python - rolling functions for GroupBy object

空扰寡人 提交于 2019-11-27 10:16:47
问题 I have a time series object grouped of the type <pandas.core.groupby.SeriesGroupBy object at 0x03F1A9F0> . grouped.sum() gives the desired result but I cannot get rolling_sum to work with the groupby object. Is there any way to apply rolling functions to groupby objects? For example: 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 However, I would like to have something like: id x 0 a 0 1 a 1 2 a 3 3 b