Recently I got a dataset that has continuous data from day 1 to day k, now I'm trying to use Pandas to create a new dataset from this, apply a time window of size n+1 (that takes the first n rows of data as 'x' and the _n+1_th row of data as 'y') to roll from top to down of the dataset.
I've tried using the apply() function but it only takes one row of data at a time, since for my problem I want to take also the following n rows of data as input, so I wrote a for loop but it is time-consuming.
n = 3
x = []
y = []
for idx in devices.index:
x.append(devices.iloc[idx:idx + n, 4:49].values)
y.append(devices.iloc[idx:idx + n + 1, 'ALARM'].values)
if idx + n + 1 == devices.index[-1]:
break
I was wondering if there's an alternative way to replace the for-loop? Thanks for any help!