Merge the first row with the column headers in a dataframe

前端 未结 3 333
野性不改
野性不改 2021-01-13 01:56

I am trying to clean up a Excel file for some further research. Problem that I have, I want to merge the first and second row. The code which I have now:

xl         


        
3条回答
  •  有刺的猬
    2021-01-13 02:38

    I think you need numpy.concatenate, similar principe like cᴏʟᴅsᴘᴇᴇᴅ answer:

    df.columns = np.concatenate([df.iloc[0, :2], df.columns[2:]])
    df = df.iloc[1:].reset_index(drop=True)
    print (df)
      Sample type Concentration     A     B    C          D          E          F  \
    0       Water          9200  95.5  21.0  6.0  11.942308  64.134615  21.498560   
    1       Water          9200  94.5  17.0  5.0   5.484615  63.205769  19.658560   
    2       Water          9200  92.0  16.0  3.0  11.057692  62.586538  19.813120   
    3       Water          4600  53.0   7.5  2.5   3.538462  35.163462   6.876207   
    
              G         H  
    0  5.567840  1.174135  
    1  4.968000  1.883444  
    2  5.192480  0.564835  
    3  1.641724  0.144654  
    

提交回复
热议问题