pandas.core.window.expanding.Expanding.corr#
- Expanding.corr(other=None, pairwise=None, ddof=1, numeric_only=False)[源代码]#
计算扩展相关性。
- Parameters:
- otherSeries 或 DataFrame,可选
如果未提供,则默认为 self 并产生成对输出。
- pairwise布尔值,默认为 None
如果为 False,则仅使用 self 和 other 之间的匹配列,并且输出为 DataFrame。如果为 True,则计算所有成对组合,并且在输入为 DataFrame 时,输出为 MultiIndexed DataFrame。在缺失元素的情况下,仅使用完整的成对观测值。
- numeric_onlybool,默认 False
仅包括浮点数、整数、布尔列。
在 1.5.0 版本加入.
- Returns:
- Series 或 DataFrame
返回类型与原始对象相同,并具有
np.float64数据类型。
参见
cov计算协方差的类似方法。
numpy.corrcoefNumPy Pearson 相关系数计算。
pandas.Series.expanding调用 Series 数据的 expanding。
pandas.DataFrame.expanding调用 DataFrames 的 expanding。
pandas.Series.corr聚合 Series 的相关系数。
pandas.DataFrame.corr聚合 DataFrame 的相关系数。
Notes
此函数使用 Pearson 的相关系数定义 (https://en.wikipedia.org/wiki/Pearson_correlation_coefficient)。
当未指定 other 时,输出将是自相关(例如,全部为 1),除非输入为
DataFrame且 pairwise 设置为 True。对于相等值的序列的相关性,函数将返回
NaN;这是由于 0/0 除法错误。当 pairwise 设置为 False 时,将仅使用 self 和 other 之间的匹配列。
当 pairwise 设置为 True 时,输出将是一个 MultiIndex DataFrame,其中第一级是原始索引,第二级是 other DataFrame 的列。
在缺失元素的情况下,将只使用完整的成对观测值。
Examples
>>> 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().corr(ser2) a NaN b 1.000000 c 0.981981 d 0.975900 dtype: float64