在python中滚动累积函数

时间:2019-11-02 16:34:20

标签: python pandas

所有,我在这里找到了一种在Python中滚动累积产品的解决方案- prior solution

但是当我尝试实现此功能时,我得到以下输出-

AttributeError: module 'pandas' has no attribute 'rolling_apply'

我认为pandas在较新的版本中删除了此功能,有人针对数据帧中的列滚动cumprod()是否有最新的解决方案?

谢谢!

编辑

全部,谢谢您的留言。我尝试了此操作-link-并遇到了与以前相同的AttributeError: module 'pandas' has no attribute 'rolling_apply'问题。下图是数据框和预期输出的示例。这将是raw_data中最后两行数据的滚动累积量。

enter image description here

1 个答案:

答案 0 :(得分:0)

全部弄清楚,rolling_apply已弃用。此功能有效-

df['output'] = df['input'].rolling(5).apply(lambda x: x.prod())

感谢您的帮助!