Merge MultiIndex columns together into 1 level [duplicate]
问题 This question already has answers here : Pandas - How to flatten a hierarchical index in columns (16 answers) Closed 2 years ago . Here's some data from another question: date type value 1/1/2016 a 1 1/1/2016 b 2 1/1/2016 a 1 1/1/2016 b 4 1/2/2016 a 1 1/2/2016 b 1 Run this line of code: x = df.groupby(['date', 'type']).value.agg(['sum', 'max']).unstack() x should look like this: sum max type a b a b date 1/1/2016 2 6 1 4 1/2/2016 1 1 1 1 I want to combine the columns on the upper and lower