Pandas reshape dataframe by adding a column level based on the value of another column [duplicate]
问题 This question already has answers here : How to pivot a dataframe (2 answers) Closed 9 months ago . I have a pandas dataframe and I would like to add a column level to split specific columns ( metric_a , metric_b , metric_c ) into several subcolumns based on the value of another column ( parameter ). Current data format: participant param metric_a metric_b metric_c 0 alice a 0,700 0,912 0,341 1 alice b 0,736 0,230 0,370 2 bob a 0,886 0,364 0,995 3 bob b 0,510 0,704 0,990 4 charlie a 0,173 0