How to sort a Pandas DataFrame according to multiple criteria?

后端 未结 5 642
独厮守ぢ
独厮守ぢ 2020-12-24 02:21

I have the following DataFrame containing song names, their peak chart positions and the number of weeks they spent at position no 1:

                                


        
5条回答
  •  情歌与酒
    2020-12-24 02:54

    In case, if the dtypes of 'Peak' and 'Week' are not 'int' or 'float', then use the following command.

    df.convert_objects(convert_numeric=True).sort_values(['Peak', 'Weeks'], ascending=[True, False], inplace=True)
    

提交回复
热议问题