how to sort pandas dataframe from one column

后端 未结 6 1192
感情败类
感情败类 2020-11-22 06:35

I have a data frame like this:

print(df)

        0          1     2
0   354.7      April   4.0
1    55.4     August   8.0
2   176.5   December  12.0
3    9         


        
6条回答
  •  难免孤独
    2020-11-22 07:13

    Just adding some more operations on data. Suppose we have a dataframe df, we can do several operations to get desired outputs

    ID         cost      tax    label
    1       216590      1600    test      
    2       523213      1800    test 
    3          250      1500    experiment
    
    (df['label'].value_counts().to_frame().reset_index()).sort_values('label', ascending=False)
    

    will give sorted output of labels as a dataframe

        index   label
    0   test        2
    1   experiment  1
    

提交回复
热议问题