Calculate correlation between all columns of a DataFrame and all columns of another DataFrame?

前端 未结 4 1832
你的背包
你的背包 2020-12-15 09:53

I have a DataFrame object stocks filled with stock returns. I have another DataFrame object industries filled with industry returns. I want to find

4条回答
  •  被撕碎了的回忆
    2020-12-15 09:59

    And here's a one-liner that uses apply on the columns and avoids the nested for loops. The main benefit is that apply builds the result in a DataFrame.

    df1.apply(lambda s: df2.corrwith(s))
    

提交回复
热议问题