【发布时间】:2014-11-11 16:52:38
【问题描述】:
>>> test.val.cumsum()
0 11
1 13
2 56
3 60
4 65
Name: val, dtype: int64
如何从累积和中获取原始值?我必须得到[11,2,43,4,5]
【问题讨论】:
标签: python pandas dataframe cumulative-sum
>>> test.val.cumsum()
0 11
1 13
2 56
3 60
4 65
Name: val, dtype: int64
如何从累积和中获取原始值?我必须得到[11,2,43,4,5]
【问题讨论】:
标签: python pandas dataframe cumulative-sum
您可以使用diff() 系列方法(用fillna 替换系列中的第一个值):
>>> s = pd.Series([11, 13, 56, 60, 65])
>>> s.diff().fillna(s)
0 11
1 2
2 43
3 4
4 5
dtype: float64
【讨论】: