pandas.Series.corr

Compute correlation with other Series, excluding missing values.

param other
Series

Series with which to compute the correlation.

param method
{‘pearson’, ‘kendall’, ‘spearman’} or callable
  • 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 .. versionadded:: 0.24.0

param min_periods
int, optional

Minimum number of observations needed to have a valid result.

return

float Correlation with other.

Limitations

  • Parameter method is supported only with default value ‘pearson’

Examples

Compute correlation with other Series, excluding missing values.
import numpy as np
import pandas as pd
from numba import njit


@njit
def series_corr():
    s1 = pd.Series([3.2, -10, np.nan, 0.23, 9.2])
    s2 = pd.Series([5., 0, 3.3, np.nan, 9.2])

    return s1.corr(s2)  # Expect value: 0.98673...


print(series_corr())
$ python ./series/series_corr.py
0.9867362434412106

See also

Series.cov

Compute covariance with Series, excluding missing values.