数据框的累积或滚动产品
问题说明
我有一个带有一列的数据框,我只是想添加另一列,该列采用原始列的滚动乘积.我已经搜索了一段时间,但这似乎是一种基本功能-不确定是否丢失了某些内容.想要将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
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfhcjf
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22