Assuming I have a Pandas dataframe similar to the below, how would I get the rolling correlation (for 2 days in this example) between 2 specific columns and group by the 'ID' column? I am familiar with the Pandas rolling_corr() function but I cannot figure out how to combine that with the groupby() clause.
What I have:
ID Date Val1 Val2
A 1-Jan 45 22
A 2-Jan 15 66
A 3-Jan 55 13
B 1-Jan 41 12
B 2-Jan 87 45
B 3-Jan 82 66
C 1-Jan 33 34
C 2-Jan 15 67
C 3-Jan 46 22
What I need:
ID Date Val1 Val2 Rolling_Corr
A 1-Jan 45 22
A 2-Jan 15 66 0.1
A 3-Jan 55 13 0.16
B 1-Jan 41 12
B 2-Jan 87 45 0.15
B 3-Jan 82 66 0.05
C 1-Jan 33 34
C 2-Jan 15 67 0.09
C 3-Jan 46 22 0.11
Thanks!