I have two data frames with 200 columns each. For illustration I am using only 3 columns here.
Dataframe df1 as:
A B C
1/4/2017 5 6 6
1/5/2017 5 2 1
1/6/2017 6 2 10
1/9/2017 1 9 10
1/10/2017 6 6 4
1/11/2017 6 1 1
1/12/2017 1 7 10
1/13/2017 8 9 6
Dataframe df2:
A D B
1/4/2017 8 10 2
1/5/2017 2 1 8
1/6/2017 6 6 6
1/9/2017 1 8 1
1/10/2017 10 6 2
1/11/2017 10 2 4
1/12/2017 5 4 10
1/13/2017 5 2 8
I want to calculate the following correlation matrix for corresponding columns of df1 and df2:
A B
1/4/2017
1/5/2017
1/6/2017 0.19 -0.94
1/9/2017 0.79 -0.96
1/10/2017 0.90 -0.97
1/11/2017 1.00 -1.00
1/12/2017 1.00 0.42
1/13/2017 0.24 0.84
i.e. using trailing 3 day historical data for same columns of df1 and df2, I need to find the correlation matrix.
so, I calculated corr([5, 5, 6], [8, 2, 6]) = 0.19 where [5,5,6] is from df1['A'] and [8,2,6] is from df2['A']
Since, I have 200 columns each I am finding it extremely cumbersome to run a for loop two times. First loop through columns and second using trailing 3 day lag data.