Sort dataframe by first column, Pandas

后端 未结 1 1749
长发绾君心
长发绾君心 2021-01-17 23:00

I have a dataframe with one column, which I would like to sort. Typing following code gives me a sorted dataframe:

sort = tst.sort([\"Mean\"], ascending = F         


        
1条回答
  •  醉梦人生
    2021-01-17 23:44

    I think you can select first column by tst.columns[0], better is use sort_values because sort return warning:

    FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)

    sort = tst.sort_values(tst.columns[0], ascending = False)
    

    print (tst)
                    Mean
    SIMULATION          
    Sim_213     0.845990
    Sim_758     1.351917
    Sim_830     0.921284
    Sim_295     0.870272
    Sim_215     1.072942
    Sim_830     0.921284
    Sim_295     0.870272
    Sim_440     0.822394
    
    print (tst.columns[0])
    Mean
    
    sort = tst.sort_values(tst.columns[0], ascending = False)
    print (sort)
                    Mean
    SIMULATION          
    Sim_758     1.351917
    Sim_215     1.072942
    Sim_830     0.921284
    Sim_830     0.921284
    Sim_295     0.870272
    Sim_295     0.870272
    Sim_213     0.845990
    Sim_440     0.822394
    

    0 讨论(0)
提交回复
热议问题