1

I have two dataframes as given below.

>>> df1
   c1  c2
0  10  10
1  20  11
2  40  15
3   9  20
4  13  27
>>> df2
    k1   k2
0  100  100
1  200  115
2  400  159
3   80  202
4   90  270

I would to compute correlation between Ks and Cs, something like given below

>>df3
          c1      c2
   k1     .99     -0.31
   k2     -0.16     .98

Assuming data represented in df3 is correct , .99 is correlation coefficient between c1 & k1 , .35 is between c2 & k1 so on .. How this can be computed?

Bharat Sharma
  • 1,081
  • 3
  • 11
  • 23

1 Answers1

0

I think you need something like this,

a=df1.columns.values
b=df2.columns.values
print   [df1[u].corr(df2[v]) for u,v in  list(itertools.product(a, b))]
Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111