How to find correlation in python?

Pandas DataFrame.corr()

The main task of the DataFrame.corr() method is to find the pairwise correlation of all the columns in the DataFrame. If any null value is present, it will automatically be excluded.

It also ignores non-numeric data type columns from the DataFrame.


DataFrame.count(axis=0, level=None, numeric_only=False)



  • pearson: standard correlation coefficient.
  • kendall: Kendall Tau correlation coefficient.
  • spearman: Spearman rank correlation.
  • callable: callable with input two 1d ndarrays that returns a float value.

min_periods: It is an optional parameter that requires a minimum number of observations per pair of columns to return a valid result. Currently it is only available for the Pearson and Spearman correlation .


It returns a DataFrame correlation matrix.


>>>defhistogram_intersection(x, y):  
...     a = np.minimum(x, y).sum().round(decimals=1)  
...     return a  
>>>info = pd.DataFrame([(.6, .2), (.4, .7), (.3, .5), (.5, .2)],  
...                   columns=['Pen', 'Pencil'])  


    Pen  Pencil
Pen     1.0  1.1
Pencil	1.1  1.0