I have the following data frame:|col0||----||1 ||2 ||3 ||4 ||5 ||... ||1000|
I'd like roll col0 into a data frame with a window size of 5, so the outcome would be like this:
col0 | col1 | col2 | ... | col995 |
---|---|---|---|---|
1 | 2 | 3 | ... | 996 |
2 | 3 | 4 | ... | 997 |
3 | 4 | 5 | ... | 998 |
4 | 5 | 6 | ... | 999 |
5 | 6 | 7 | ... | 1000 |
col0 .... col9951 2 3 ... 9962 3 4 ... 9973 4 5 ... 9984 5 6 ... 9995 6 7 ... 1000
I've tried using loops and "iloc" which would produce correct results, but as the original data frame gets much longer, it would take too long to finish. Is there any way to do it faster, more efficiently in Python?
Thank you.