Move column by name to front of table in pandas

后端 未结 9 926
你的背包
你的背包 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:08

    Here is a very simple answer to this.

    Don't forget the two (()) 'brackets' around columns names.Otherwise, it'll give you an error.

    
    # here you can add below line and it should work 
    df = df[list(('Mid','Upper', 'Lower', 'Net','Zsore'))]
    df
    
                                 Mid   Upper   Lower  Net  Zsore
    Answer option                                                
    More than once a day          2   0.22%  -0.12%   0%    65 
    Once a day                    3   0.32%  -0.19%   0%    45
    Several times a week          4   2.45%   1.10%   2%    78
    Once a week                   6   1.63%  -0.40%   1%    65
    

提交回复
热议问题