`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
我尝试了pandas pivot_table column names这个链接选项,但它似乎并不适合我。
附加样本数据。 https://drive.google.com/open?id=1dGDb4tjyRKzjVIH-BNEy0NJvmLxbiA2g
答案 0 :(得分:2)
您可以删除索引0处的列级别,然后重新构建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