Reputation: 18638
>>> 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]
Upvotes: 2
Views: 1271
Reputation: 176850
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
Upvotes: 4