def Pearson(r, n=len(dat)):
    r = max(min(r, 1.0), -1.0)
df = n - 2
if abs(r) == 1.0:
    prob = 0.0
else:
    t_squared = r ** 2 * (df / ((1.0 - r) * (1.0 + r)))
prob = betai(0.5 * df, 0.5, df / (df + t_squared))
return r, prob
Python pandas function applied to all pairwise combinations of rows