How to Calculate Correlation Between Two Columns in Pandas?
In this article, we will discuss how to calculate the correlation between two columns in pandas
Correlation is used to summarize the strength and direction of the linear association between two quantitative variables. It is denoted by r and values between -1 and +1. A positive value for r indicates a positive association, and a negative value for r indicates a negative association.
By using corr() function we can get the correlation between two columns in the dataframe.
- dataframe is the input dataframe
- first_column is correlated with second_column of the dataframe
Example 1: Python program to get the correlation among two columns
column1 column2 column3 0 12 67 34 1 23 54 23 2 45 32 56 3 67 1 23 -0.9970476685163736 0.07346999975265099 0.0
It is also possible to get element-wise correlation for numeric valued columns using just corr() function.
Example 2: Get the element-wise correlation
column1 column2 column3 column1 1.000000 -0.997048 0.00000 column2 -0.997048 1.000000 0.07347 column3 0.000000 0.073470 1.00000
My Personal Notes arrow_drop_up
Please Login to comment...