I begin with a Correlation matrix DataFrame similar to this:
x y z
x 1.0 0.4 0.25
y 0.2 1.0 -0.44
z -0.3 -0.3 1.0
I want to know how to create a new DataFrame that will store all column pairs and their corresponding correlation value such as: ['Column name1', 'Column name2', 'Correlation value'].
An example row: [x, y, 0.2]
Is there a way to do this with comprehension, while also ensuring that no pairs are included twice, and that correlation pairs equal to 1 are excluded?
Something like [[x, y, df.loc[x,y]] for x in df.columns for y in df.columns