Pandas: Apply function to each pair of columns
问题 Function f(x,y) that takes two Pandas Series and returns a floating point number. I would like to apply f to each pair of columns in a DataFrame D and construct another DataFrame E of the returned values, so that f(D[i],D[j]) is the value of the i th row and j th column. The straightforward solution is to run a nested loop over all pairs of columns: E = pd.DataFrame([[f(D[i], D[j]) for i in D] for j in D], columns=D.columns, index=D.columns) But is there a more elegant solution that perhaps