pandas.core.groupby.DataFrameGroupBy.corrwith #
- DataFrameGroupBy。corrwith ( other , axis = _NoDefault.no_default , drop = False , method = 'pearson' , numeric_only = False ) [来源] #
计算成对相关性。
成对相关性是在 DataFrame 的行或列与 Series 或 DataFrame 的行或列之间计算的。在计算相关性之前,数据帧首先沿两个轴对齐。
- 参数:
- 其他数据框、系列
用于计算相关性的对象。
- 轴{0 或 'index', 1 或 'columns'}, 默认 0
要使用的轴。 0 或“索引”按行计算,1 或“列”按列计算。
- drop bool, 默认 False
从结果中删除缺失的索引。
- 方法{'pearson', 'kendall', 'spearman'} 或可调用
相关法:
皮尔逊:标准相关系数
kendall :Kendall Tau 相关系数
Spearman :斯皮尔曼等级相关
- callable:可调用,输入两个 1d ndarray
并返回一个浮点数。
- numeric_only布尔值,默认 False
仅包含float、int或boolean数据。
1.5.0 版本中的新增内容。
版本 2.0.0 中更改:默认值为
numeric_only
nowFalse
。
- 返回:
- 系列
成对相关性。
也可以看看
DataFrame.corr
计算列的成对相关性。
例子
>>> index = ["a", "b", "c", "d", "e"] >>> columns = ["one", "two", "three", "four"] >>> df1 = pd.DataFrame(np.arange(20).reshape(5, 4), index=index, columns=columns) >>> df2 = pd.DataFrame(np.arange(16).reshape(4, 4), index=index[:4], columns=columns) >>> df1.corrwith(df2) one 1.0 two 1.0 three 1.0 four 1.0 dtype: float64
>>> df2.corrwith(df1, axis=1) a 1.0 b 1.0 c 1.0 d 1.0 e NaN dtype: float64