preprocessing time sequence
There are a couple of design patterns that are contributing to slow code:

Pandas is not designed for large-scale, fast data processing.

Your code is using a for loop which can be slow.

You are manifesting the sliding window before the program needs it. It might be better to create a view on the data and then manifest the data in memory only when the training needs it.


It would be better to use NumPy with numpy.lib.stride_tricks.sliding_window_view