pby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.corr  #

DataFrame.  corr  (  _ method  =  'pearson'  _ , _ min_periods  =  1  _ , _
numeric_only  =  False  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L10975-L11087) #

    

Compute pairwise correlation of columns, excluding NA/null values.

Parameters  :

    

**method** {âpearsonâ, âkendallâ, âspearmanâ} or callable

    

Method of correlation:

  * pearson : standard correlation coefficient 

  * kendall : Kendall Tau correlation coefficient 

  * spearman : Spearman rank correlation 

  * callable: callable with input two 1d ndarrays 
    

and returning a float. Note that the returned matrix from corr will have 1
along the diagonals and will be symmetric regardless of the callableâs
behavior.

**min_periods** int, optional

    

Minimum number of observations required per pair of columns to have a valid
result. Currently only available for Pearson and Spearman correlation.

**numeric_only** bool, default False

    

Include only  float  ,  int  or  boolean  data.

New in version 1.5.0.

Changed in version 2.0.0:  The default value of ` numeric_only  ` is now `
False  ` .

Returns  :

    

DataFrame

    

Correlation matrix.

See also

[ ` DataFrame.corrwith  `
](pandas.DataFrame.corrwith.html#pandas.DataFrame.corrwith
"pandas.DataFrame.corrwith")

    

Compute pairwise correlation with another DataFrame or Series.

[ ` Series.corr  ` ](pandas.Series.corr.html#pandas.Series.corr
"pandas.Series.corr")

    

Compute the correlation between two Series.

Notes

Pearson, Kendall and Spearman correlation are currently computed using
pairwise complete observations.

  * [ Pearson correlation coefficient ](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient)

  * [ Kendall rank correlation coefficient ](https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient)

  * [ Spearmanâs rank correlation coefficient ](https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient)

Examples

    
    
    >>> def histogram_intersection(a, b):
    ...     v = np.minimum(a, b).sum().round(decimals=1)
    ...     return v
    >>> df = pd.DataFrame([(.2, .3), (.0, .6), (.6, .0), (.2, .1)],
    ...                   columns=['dogs', 'cats'])
    >>> df.corr(method=histogram_intersection)
          dogs  cats
    dogs   1.0   0.3
    cats   0.3   1.0
    
    
    
    >>> df = pd.DataFrame([(1, 1), (2, np.nan), (np.nan, 3), (4, 4)],
    ...                   columns=['dogs', 'cats'])
    >>> df.corr(min_periods=3)
          dogs  cats
    dogs   1.0   NaN
    cats   NaN   1.0
    

[ __ previous  pandas.DataFrame.clip  ](pandas.DataFrame.clip.html "previous
page") [ next  pandas.DataFrame.corrwith  __ ](pandas.DataFrame.corrwith.html
"next page")

__ On this page

  * ` DataFrame.corr()  `

[ __ Show Source ](../../_sources/reference/api/pandas.DataFrame.corr.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.