pandas.DataFrame.corrwith#
- DataFrame.corrwith(other, axis=0, drop=False, method='pearson', numeric_only=True)[源代码]#
计算成对相关。
在DataFrame的行或列与Series或DataFrame的行或列之间计算成对关联。在计算相关性之前,首先沿两个轴对齐DataFrame。
- 参数
- otherDataFrame,系列
用来计算相关性的对象。
- axis{0或‘index’,1或‘Columns’},默认为0
要使用的轴。0或‘index’按列计算,1或‘Columns’按行计算。
- drop布尔值,默认为False
从结果中删除缺少的索引。
- method{‘Pearson’,‘Kendall’,‘Spearman’}或可调用
对比方法:
皮尔逊:标准相关系数
Kendall:Kendall Tau相关系数
斯皮尔曼:斯皮尔曼等级相关
- 可调用:可通过输入两条一维雷达进行调用
并返回一个浮点数。
- numeric_only布尔值,默认为True
仅包括 float , int 或 boolean 数据。
1.5.0 新版功能.
- 退货
- 系列
两两相关。
参见
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