Say I have a data frame like this:
x y z
timestamp
some_date_1 5 2 4
some_date_2 1 2 6
some_date_3 7 3 5
...
some_date_50 4 3 6
and I want to apply a sliding window of size 10 (call this a variable window_size
) with a 50% overlap (make this a variable step_size
that's half of window_size
) on the x
, y
, and z
columns. Therefore, I would print the first 10 rows from 0 - 9. Afterwards, I would print 5 - 14, 10 - 19, 15 - 24, etc.
How would I do that if I had a function:
def sliding_window(df, window_size, step_size):
Assume timestamp
is datetime.
I want to have separate structures for each window. So, for example, I want to have a separate DataFrame for the first ten rows, and then another for the next ten etc.
For simplicity, I will show an example with window size 4 and step size of 2.
x y z
timestamp
some_date_1 5 2 4
some_date_2 1 2 6
some_date_3 2 3 1
some_date_4 5 4 4
x y z
timestamp
some_date_3 2 3 1
some_date_4 5 4 4
some_date_5 6 7 9
some_date_6 2 1 8