【发布时间】:2019-12-29 00:14:03
【问题描述】:
我想计算一个简单的指数系列,但不知何故它不起作用。数据框有两列:索引列和要添加的百分比变化:
Indice PerChange
1 1 0.024412
2 1 0.036074
3 1 0.027329
4 1 0.027981
这是我的代码:
df3["Indice"] = df3["Indice"] * (df3["PerChange"] + df3["Indice"].shift(1))
df3.at[1, 'Indice'] = 1
我得到以下输出:
Indice PerChange
1 1.000000 0.024412
2 1.036074 0.036074
3 1.027329 0.027329
4 1.027981 0.027981
但是,我想看到的是:
Indice PerChange
1 1.000000 0.024412
2 1.036074 0.036074
3 1.064388 0.027329
4 1.094171 0.027981
【问题讨论】:
标签: pandas indexing time-series