'Group columns in dataframe, Multiindex pandas

I am calculating some correlations for a set of measures. dataframe

For each measure, I have a data frame of the look attached, which I will join in one data frame.

I want to add multilevel indexing, with the name of the measure, above the columns I have. What is the best way of doing so?



Solution 1:[1]

You can use corr to find the correlations within your columns

df.corr()

Use this to split CI95% column into two columns

df[['CI95%_1','CI95%_2']] = pd.DataFrame(df['CI95%'].tolist(), index= df.index)

Then use corr()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1