DataFrame.corr(method='pearson', min_periods=1, numeric_only=False)
method | {‘pearson’, ‘kendall’, ‘spearman’} 或可调用对象
|
df = pd.DataFrame([(.2, .3), (.0, .6), (.6, .0), (.2, .1)],
columns=['dogs', 'cats'])
df
'''
dogs cats
0 0.2 0.3
1 0.0 0.6
2 0.6 0.0
3 0.2 0.1
'''
df.corr()
'''
dogs cats
dogs 1.000000 -0.851064
cats -0.851064 1.000000
'''
def histogram_intersection(a, b):
v = np.minimum(a, b).sum()
return v
'''
自定义函数:输入两列,返回一个数值
'''
df.corr(method=histogram_intersection)
'''
dogs cats
dogs 1.0 0.3
cats 0.3 1.0
'''