-1

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

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

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

我认为熊猫在更新的版本中删除了此功能,是否有人为数据框中的列滚动 cumprod() 提供更新的解决方案?

谢谢!

编辑

大家,谢谢你的留言。我尝试了这个-链接-并遇到了与AttributeError: module 'pandas' has no attribute 'rolling_apply'以前相同的问题。数据框和预期输出的示例如下图所示。这将是 raw_data 中最后 2 行数据的滚动 cumprod。

在此处输入图像描述

4

1 回答 1

0

总而言之,rolling_apply 已被弃用。此功能有效 -

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

谢谢你的帮助!

于 2019-11-02T18:44:04.053 回答