Hello,
new_df = pd.DataFrame([old_df.iloc[:,0].rolling(window = 10).corr(old_df.iloc[:,i]) for i in range(1,7)]).T
Old_df is my original dataframe with 8 columns. I want to create a new dataframe that correlates the first column with each of the other 7 columns. Each correlation is a rolling window of length 10. The code above works fine to produce a dataframe called new_df as long as I explicitly use the name old_df.
what I want to do is generalize this list comprehension in two ways.
1) I'd like to past a list of window lengths (i.e. [10, 15]) so that two dataframes are output of the same dimensions, except that one creates the 7 correlation columns with window size 10 and the other creates the correlations with window size 15.
I know this will probably require the apply method and maybe a user defined function, but I have try many iterations and all I get is errors.
2) ideally I'd like to use the apply/map method within the code so that I don't have to name my dataframe explicitly to get an error free answer.
Thank you for any advice