DataFrame.corr(method=‘pearson’, min_periods=1)
计算列与列之间的相关系数,返回相关系数矩阵
- method : {‘pearson’, ‘kendall’, ‘spearman’}
- pearson : standard correlation coefficient
- kendall : Kendall Tau correlation coefficient
- spearman : Spearman rank correlation
解释:相关系数的取值范围为[-1, 1],当接近1时,表示两者具有强烈的正相关性,比如‘s’和‘x’;当接近-1时,表示有强烈的的负相关性,比如‘s’和‘c’,而若值接近0,则表示相关性很低.
代码:
allDf = pd.DataFrame({
'x':[0,1,2,4,7,10],
'y':[0,3,2,