-3
`KM_Data_ENG = pd.pivot_table(read_sql_KM, index=["PLACEMENT_DESC", "METRIC_DESC","BLAZE_ACTION_TYPE_DESC"],
                                     values=["ENG_INTERACTION"],columns=["BLAZE_TAG_NAME_DESC"], aggfunc=np.sum, fill_value=0, margins=True)

        KM_reset = KM_Data_ENG.reset_index()
        print KM_reset

`I have pivot table data frame which is giving me output like belowenter image description here

but i want the data like below.enter image description here

I tried pandas pivot_table column names, this link options but it doesn't seems to working for me.

sample data attached. https://drive.google.com/open?id=1dGDb4tjyRKzjVIH-BNEy0NJvmLxbiA2g

DKM
  • 1,761
  • 2
  • 19
  • 34

1 Answers1

3

You can drop the column level at index 0, and then reconstruct the DataFrame.

KM_Data_ENG.columns = KM_Data_ENG.columns.droplevel()
pd.DataFrame(KM_Data_ENG.to_records()).iloc[:5, :4]

        PLACEMENT_DESC  METRIC_DESC  BLAZE_ACTION_TYPE_DESC  TaptoDownload
0   1.VDX Rectangle...          CPE              Click-thru            0.0
1   1.VDX Rectangle...          CPE             Interaction            0.0
2   11.VDX Mobile A...          CPE               Click-thru           5.0
3   11.VDX Mobile A...          CPE             Interaction            0.0
4   2.VDX Leaderboa...          CPE              Click-thru            0.0
Ben
  • 856
  • 5
  • 9