我想用以下方式分离一个数据集:
import pandas as pd
import numpy as np
df = pd.read_csv("https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv")
sepal_length = df["sepal_length"]
sepal_length
0 5.1
1 4.9
2 4.7
3 4.6
4 5.0
...
145 6.7
146 6.3
147 6.5
148 6.2
149 5.9
Name: sepal_length, Length: 150, dtype: float64我想创建另一个数据集,尝试根据之前的10个观察值来预测这些值(假设这个数据集是有序的,并且依赖于日期)。
因此,对于我的预测值,我希望有另一个数据集,其中包含每个索引的10个先前值。这是:
10 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9
11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
...其中$ x_i $是第i个索引处的裂片长度。
发布于 2021-07-01 00:05:01
这就是你想要的:
for i in range(1,11):
df[f'feature_{i}']=df['sepal_length'].shift(i)https://stackoverflow.com/questions/68197014
复制相似问题