【发布时间】:2020-10-02 04:50:13
【问题描述】:
我有一个如下所示的数据集:
A B
5/8 2 3
6/8 4 2
7/8 3 5
8/8 3 2
我想这样结束
index1 index2 A B
5/8 5/8 2 3
6/8 4 2
6/8 6/8 4 2
7/8 3 5
7/8 7/8 3 5
8/8 3 2
etc.
也是一个可以采用数字索引的等价物。这样我就可以决定是展平数据还是为 ML 训练创建一个 3d 数组。
我已经用 df.iterrows() 完成了它,但它太慢了。我也尝试过制作这段代码:
def addDatas(x,df,window):
global dfOo #Dataset to create
if len(x)==window:
y = df.loc[x.index];
y.DateStarted = df.loc[x.index[-1]].created #index1 in table presented
dfOo = dfOo.append(y)
return 0;
dfOo= pd.DataFrame();
#created is the date index in the first table
dfTargets.rolling("5s",on="created").apply(lambda x : addDatas(x,dfTargets,5))
这两种解决方案都有效,但速度不够快,并且无法处理大量数据。我可以帮忙,但我认为一定有一种我不知道的更简单的方法来做到这一点。
【问题讨论】:
标签: time-series pandas