![](/img/trans.png)
[英]Python: How to populate Pandas column that depends on the previous value (previous row)?
[英]Generate a Column that depends on the previous value of that column 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.