Tatenda D Kavu
Tatenda D Kavu

Reputation: 41

Performing a correlation on multiple columns in pandas

Is it possible to do a correlation between multiple columns against one column in pandas? Like:

DF[['A']['B']].corr(DF['C'])

Upvotes: 4

Views: 5561

Answers (1)

jezrael
jezrael

Reputation: 862406

I believe you need corrwith and select multiple columns by list:

DF = pd.DataFrame({

         'B':[4,5,4,5,5,4],
         'C':[7,8,9,4,2,3],
         'A':[1,3,5,7,1,0],

})

print (DF[['A', 'B']].corrwith(DF['C']))
A    0.319717
B   -0.316862
dtype: float64

Upvotes: 3

Related Questions