Pandas dataframe with multiindex column – merge levels
There is potentially a better way, more pythonic way to flatten MultiIndex columns. 1. Use map and join with string column headers: grouped.columns = grouped.columns.map(‘|’.join).str.strip(‘|’) print(grouped) Output: code colour size|sum size|average size|size size|idxmax \ 0 one black 862 53.875000 16 14 1 one white 554 46.166667 12 18 2 three black 842 49.529412 17 90 … Read more