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

前端 未结 4 1823
你的背包
你的背包 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 10:19

    Quite late, but more general solution:

    def corrmatrix(df1,df2):
        s = df1.values.shape[1]
        cr = np.corrcoef(df1.values.T,df2.values.T)[s:,:s]    
        return pd.DataFrame(cr,index = df2.columns,columns = df1.columns)
    

提交回复
热议问题