Move column by name to front of table in pandas

后端 未结 9 912
你的背包
你的背包 2020-12-04 07:40

Here is my df:

                             Net   Upper   Lower  Mid  Zsore
Answer option                                                
More than once a da         


        
9条回答
  •  情歌与酒
    2020-12-04 08:01

    Here is a generic set of code that I frequently use to rearrange the position of columns. You may find it useful.

    cols = df.columns.tolist()
    n = int(cols.index('Mid'))
    cols = [cols[n]] + cols[:n] + cols[n+1:]
    df = df[cols]
    

提交回复
热议问题