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
This will work:
from scipy.stats import pearsonr column_values = [column for column in df.columns.tolist() ] df['Correlation_coefficent'], df['P-value'] = zip(*df.T.apply(lambda x: pearsonr(x[column_values ],x[column_values ]))) df_result = df[['Correlation_coefficent','P-value']]