问题
>>> test.val.cumsum()
0 11
1 13
2 56
3 60
4 65
Name: val, dtype: int64
How do I get the original values from the cumulative sum? I will have to get [11,2,43,4,5]
回答1:
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
来源:https://stackoverflow.com/questions/26870116/get-original-values-from-cumulative-sum