Pandas has the very handy function to do pairwise correlation of columns using pd.corr(). That means it is possible to compare correlations between columns of any length. For in
Why not using the "method" argument of pandas.DataFrame.corr()
:
pearson
: standard correlation coefficient.kendall
: Kendall Tau correlation coefficient.spearman
: Spearman rank correlation.callable
: callable with input two 1d ndarrays and returning a float.from scipy.stats import kendalltau, pearsonr, spearmanr
def kendall_pval(x,y):
return kendalltau(x,y)[1]
def pearsonr_pval(x,y):
return pearsonr(x,y)[1]
def spearmanr_pval(x,y):
return spearmanr(x,y)[1]
and then
corr = df.corr(method=pearsonr_pval)