polars.pearson_corr#

polars.pearson_corr(a: str | Expr, b: str | Expr, ddof: int = 1) Expr[source]#

Compute the pearson’s correlation between two columns.

Parameters:
a

Column name or Expression.

b

Column name or Expression.

ddof

Delta degrees of freedom

Examples

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