pandas.core.window.expanding.Expanding.cov # 扩大。cov ( other = None , pairwise = None , ddof = 1 , numeric_only = False ) [来源] # 计算扩展样本协方差。 参数: 其他系列或数据框,可选如果未提供,则将默认为 self 并产生成对输出。 成对布尔值,默认无如果为 False,则仅使用 self 和 other 之间的匹配列,并且输出将是一个 DataFrame。如果为 True,则将计算所有成对组合,并且在 DataFrame 输入的情况下,输出将是 MultiIndexed DataFrame。在缺少元素的情况下,仅使用完整的成对观测值。 ddof int,默认1Delta 自由度。计算中使用的除数是,其中表示元素的数量。N - ddofN numeric_only布尔值,默认 False仅包含 float、int、boolean 列。 1.5.0 版本中的新增内容。 返回: 系列或数据框返回类型与具有 dtype 的原始对象相同np.float64。 也可以看看 pandas.Series.expanding调用扩展系列数据。 pandas.DataFrame.expanding使用 DataFrame 调用扩展。 pandas.Series.cov聚合系列的 cov。 pandas.DataFrame.cov聚合 DataFrame 的 cov。 例子 >>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) >>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd']) >>> ser1.expanding().cov(ser2) a NaN b 0.500000 c 1.500000 d 3.333333 dtype: float64