繁体   English   中英

生成一个依赖于该列之前值的列 scala/python

[英]Generate a Column that depends on the previous value of that column scala/python

我需要生成一个取决于该列的先前值的列。 公式将是这样的:

活跃客户 t = t-1 中的活跃客户 + t 中的招聘 - t 中的取消

我拥有的数据集有新的招聘和取消列,累积的活动策略是我想要的输出。

在此处输入图片说明

欢迎使用 scala 或 python 替代品! 谢谢!!

您可以使用函数.cumsum()解决这个似乎具有累积性质的问题:

df['active customers t'] = (df['New Hirings'] - df['Cancelation']).cumsum()

输出:

   New Hirings  Cancelations  Cumulative Active Customers
0            1             1                            0
1            1             0                            1
2            2             0                            3
3            2             0                            5
4            5             1                            9
5            0             1                            8
6            7             0                           15
7            2             3                           14
8            0             2                           12
9            2             1                           13

另外,对于未来的问题,请尝试将您的数据作为文本而不是图片发布!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM