• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

数据框的累积或滚动产品

用户头像
it1352
帮助1

问题说明

我有一个带有一列的数据框,我只是想添加另一列,该列采用原始列的滚动乘积.我已经搜索了一段时间,但这似乎是一种基本功能-不确定是否丢失了某些内容.想要将B列作为输出.

Hi I have a dataframe with a column and i'd simply like to add another column that takes the rolling product of the original column. I've been googling around for a while but this seems like such a basic functionality - not sure if I'm missing something. Id to like to get Column B as an output.

A   B
1   1
2   2
3   6
4   24
5   120
6   720
7   5040

我本质上是在寻找类似的东西(如果存在)

Im essentially looking for something like this if it existed:

data ['B'] =数据['A'].rolling(window = 1).product()

data['B'] = data['A'].rolling(window=1).product()

I found this post from earlier but it seems to be using rolling_apply which is no longer active?:

如何在Pandas DataFrame上计算滚动累积产品 a>

我曾尝试在此处使用类似的解决方案,但似乎无法正常工作.

i've tried using a similar solution here like this but it doesn't seem to be working.

dftest= pd.DataFrame([1,2,3,4,5,6,7],columns=['A'])
dftest['cum']=dftest['A'].rolling(1).apply(lambda x:x.prod())

输出:

   A  cumprod
0  1  1.0
1  2  2.0
2  3  3.0
3  4  4.0
4  5  5.0
5  6  6.0
6  7  7.0

正确答案

#1

好像您想要查看全文

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhcjf
系列文章
更多 icon
同类精品
更多 icon
继续加载