pandas.Series.cov

Compute covariance with Series, excluding missing values.

param other
Series

Series with which to compute the covariance.

param min_periods
int, optional

Minimum number of observations needed to have a valid result.

return

float Covariance between Series and other normalized by N-1 (unbiased estimator).

Examples

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


@njit
def series_cov():
    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.cov(s2)  # Expect value: 44.639...


print(series_cov())
$ python ./series/series_cov.py
44.63999999999999

See also

Series.corr

Compute correlation with other Series, excluding missing values.