Pandas - How to flatten a hierarchical index in columns

后端 未结 17 1065
忘掉有多难
忘掉有多难 2020-11-22 02:55

I have a data frame with a hierarchical index in axis 1 (columns) (from a groupby.agg operation):

     USAF   WBAN  year  month  day  s_PC  s_CL         


        
17条回答
  •  甜味超标
    2020-11-22 03:06

    I'll share a straight-forward way that worked for me.

    [" ".join([str(elem) for elem in tup]) for tup in df.columns.tolist()]
    #df = df.reset_index() if needed
    

提交回复
热议问题