I am currently starting to learn Pandas and struggling to do a task with it. What I am trying to do is to augment the data stored in a dataframe by combining two succesive rows with an increasing overlap between them. Just like a rolling window.
I believe the question can exemplified with this small dataframe:
df = pd.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], columns=['A', 'B', 'C', 'D'])
which gives:
A B C D
0 1 2 3 4
1 5 6 7 8
2 9 10 11 12
With it, what I want to accomplish but I don't know how to, is a dataframe like the next one:
A B C D
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
6 7 8 9 10
7 8 9 10 11
8 9 10 11 12
As if we were using multiple rolling windows between each pair of the initial dataframe. Note that I am not using this specific dataframe (the values are not really ordered like 1,2,3,4...). What I am using is a general dataframe imported from a csv.
Is this possible?, thanks in advance!
Edit
Thanks to all the responses. Both answers given by anky and Shubham Sharma work perfect. Here are the results obtained by using both of them with my real dataframe:
Initial dataframe
After adding multiple rolling windows as my question needed
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…