I'm wondering if there is a fast way to do running correlation in Python with one fixed series? I've tried to use Pandas and for example: df1.rolling(4).corr(df2). However, it requires two DataFrames to have the same length. Is there a way to do similiar to the above Pandas example, but with one DataFrame being fixed?
To clarify, I would want to calculate the correlation coefficent between df2 below and the values in df1.
Example: First correlation between df2 and df1.loc[0:3] Second correlation between df2 and df1.loc[1:4]
etc.
I've managed to do this by creating a loop. However, I find it inefficent when working with larger DataFrames.
df1 = pd.DataFrame([1,3,2,4,5,6,3,4])
df2 = pd.DataFrame([1,2,3,2])
