sting.assert_frame_equal.html)
    * [ polars.testing.assert_frame_not_equal ](../../api/polars.testing.assert_frame_not_equal.html)
    * [ polars.testing.assert_series_equal ](../../api/polars.testing.assert_series_equal.html)
    * [ polars.testing.assert_series_not_equal ](../../api/polars.testing.assert_series_not_equal.html)
    * [ polars.testing.parametric.dataframes ](../../api/polars.testing.parametric.dataframes.html)
    * [ polars.testing.parametric.series ](../../api/polars.testing.parametric.series.html)
    * [ polars.testing.parametric.column ](../../api/polars.testing.parametric.column.html)
    * [ polars.testing.parametric.columns ](../../api/polars.testing.parametric.columns.html)
    * [ polars.testing.parametric.create_list_strategy ](../../api/polars.testing.parametric.create_list_strategy.html)
    * [ polars.testing.parametric.load_profile ](../../api/polars.testing.parametric.load_profile.html)
    * [ polars.testing.parametric.set_profile ](../../api/polars.testing.parametric.set_profile.html)

  * [ Metadata ](../../metadata.html) __
    * [ polars.build_info ](../../api/polars.build_info.html)
    * [ polars.get_index_type ](../../api/polars.get_index_type.html)
    * [ polars.show_versions ](../../api/polars.show_versions.html)
    * [ polars.thread_pool_size ](../../api/polars.thread_pool_size.html)
    * [ polars.threadpool_size ](../../api/polars.threadpool_size.html)

  * [ __ ](../../../index.html)
  * [ Python API reference ](../../index.html)
  * __
  * [ Functions ](../functions.html)
  * polars.corr 

#  polars.corr  #

polars.  corr  (

     _ a  :  IntoExpr  _ , 
     _ b  :  IntoExpr  _ , 
     _ *  _ , 
     _ method  :  CorrelationMethod  =  'pearson'  _ , 
     _ ddof  :  [ int  ](https://docs.python.org/3/library/functions.html#int "\(in Python v3.12\)") =  1  _ , 
     _ propagate_nans  :  [ bool  ](https://docs.python.org/3/library/functions.html#bool "\(in Python v3.12\)") =  False  _ , 
)  →  Expr  [ [source]  ](https://github.com/pola-rs/polars/blob/main/py-
polars/polars/functions/lazy.py#L736-L813) #

    

Compute the Pearson’s or Spearman rank correlation correlation between two
columns.

Parameters  :

    

**a**

    

Column name or Expression.

**b**

    

Column name or Expression.

**ddof**

    

“Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof,
where N represents the number of elements. By default ddof is 1.

**method** {‘pearson’, ‘spearman’}

    

Correlation method.

**propagate_nans**

    

If ` True  ` any ` NaN  ` encountered will lead to ` NaN  ` in the output.
Defaults to ` False  ` where ` NaN  ` are regarded as larger than any finite
number and thus lead to the highest rank.

Examples

Pearson’s correlation:

    
    
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, 2],
    ...         "c": ["foo", "bar", "foo"],
    ...     }
    ... )
    >>> df.select(pl.corr("a", "b"))
    shape: (1, 1)
    ┌──────────┐
    │ a        │
    │ ---      │
    │ f64      │
    ╞══════════╡
    │ 0.544705 │
    └──────────┘
    

Spearman rank correlation:

    
    
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, 2],
    ...         "c": ["foo", "bar", "foo"],
    ...     }
    ... )
    >>> df.select(pl.corr("a", "b", method="spearman"))
    shape: (1, 1)
    ┌─────┐
    │ a   │
    │ --- │
    │ f64 │
    ╞═════╡
    │ 0.5 │
    └─────┘
    

[ __ previous  polars.concat_str  ](polars.concat_str.html "previous page") [
next  polars.count  __ ](polars.count.html "next page")

__ On this page

  * ` corr()  `

© Copyright 2020, Ritchie Vink.  

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

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