pandasdataframestatisticsmulti-index

how to create basic level DataFrame by using dictionary


I have a DataFrame like this

enter image description here

but I want to create DataFrame like this ;

enter image description here

Actually, I just want to append salary up to min, max and mean


Solution

  • Try this

    df = df.set_index('department_name')
    # add salary as level=0 column name
    df.columns = pd.MultiIndex.from_product([['salary'], df.columns])