我在Jupyter笔记本中有以下代码:
data['2 day change'] = data['Close'].pct_change(periods = 2) * 100
data['5 day change'] = data['Close'].pct_change(periods = 5) * 100
data['10 day change'] = data['Close'].pct_change(periods = 10) * 100
data['20 day change'] = data['Close'].pct_change(periods = 20) * 100
data['90 day change'] = data['Close'].pct_change(periods = 90) * 100
data['1 day after'] = (data['Close'] - data['Close'].shift(1))/data['Close'] * 100
data['2 day after'] = (data['Close'] - data['Close'].shift(2))/data['Close'] * 100
data['5 day after'] = (data['Close'] - data['Close'].shift(5))/data['Close'] * 100
data['20 day after'] = (data['Close'] - data['Close'].shift(20))/data['Close'] * 100
data['90 day after'] = (data['Close'] - data['Close'].shift(90))/data['Close'] * 100
data['1 day after'].shift(-1)
data['adjusted'] = data['1 day after'].shift(-1)
该脚本的目的是计算特定时间段内的更改,然后将值分配给确切的日期索引(第一列)。
我想问为什么代码data['1 day after'].shift(-1)
不起作用?为了正确分配和移动数据,我必须首先在数据集中添加一个新列,然后执行切换操作。
您能帮我解决一下吗?