figure - six-month aapl return correlation to & suppose you wanted to compute the correlation of the & index with many stocks at once writing loop and creating new dataframe would be easy but maybe get repetitiveso if you pass timeseries and dataframea function like rolling_corr will compute the correlation of the timeseries (spx_rets in this casewith each column in the dataframe see figure - for the plot of the resultin [ ]corr pd rolling_corr(returnsspx_rets min_periods= in [ ]corr plot(moving window functions www it-ebooks info