I have a pandas dataframe in the following form:
id2_cond1 id2_cond2 id2_cond3 id2_cond4
id2_cond1 1.000000 0.819689 -0.753702 -0.617213
id2_cond2 0.819689 1.000000 -0.554437 -0.295122
id2_cond3 -0.753702 -0.554437 1.000000 0.939336
id2_cond4 -0.617213 -0.295122 0.939336 1.000000
What I want to do is to convert the dataframe into the following form:
cond1_cond2 cond1_cond3 cond1_cond4 cond2_cond3 cond2_cond4 cond3_cond4
id2 0.8196886 -0.7537023 -0.6172134 -0.554437 -0.2951216 0.9393364
I can do this properly using the following script:
df_tmp = pd.DataFrame(index=[identifier], columns=cols)
counter = 0
for x in range(len(df)):
for y in range(x + 1, len(df)):
df_tmp.ix[0, counter] = df.ix[x, y]
counter += 1
print(df_tmp)
The problem with this approach is that I have to predefine the columns and I have to know the order.
cols = ["cond1_cond2", "cond1_cond3", "cond1_cond4", "cond2_cond3", "cond2_cond4", "cond3_cond4"]
Is there a better way of converting this dataframe, that creates automatically the different combinations?