从累积总和中获取原始值 [英] Get original values from cumulative sum
本文介绍了从累积总和中获取原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
>>> test.val.cumsum()
0 11
1 13
2 56
3 60
4 65
Name: val, dtype: int64
如何从累积和中获取原始值?我将必须获取[11,2,43,4,5]
How do I get the original values from the cumulative sum? I will have to get [11,2,43,4,5]
推荐答案
您可以使用diff()
系列方法(用fillna
替换系列中的第一个值):
You could use the diff()
Series method (with fillna
to replace the first value in the series):
>>> s = pd.Series([11, 13, 56, 60, 65])
>>> s.diff().fillna(s)
0 11
1 2
2 43
3 4
4 5
dtype: float64
这篇关于从累积总和中获取原始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文