I have a dataset that looks like this:
A B
5/8 2 3
6/8 4 2
7/8 3 5
8/8 3 2
and I want to finish like this
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.
and also an equivalent that would take numeric indexes. This way I can decide whether flatten the data or create a 3d array for the ML training.
I have done it with df.iterrows() but it so slow. I also tried by making this code:
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))
Both of these solutions work but they aren´t fast enough and not usable with big chunks of data. I can help but think that there must be an easier way to do this that I don´t know.
