Sort Pandas DataFrame by value

前端 未结 2 1075
攒了一身酷
攒了一身酷 2020-12-11 14:34

I Know this question has a lot of answers, for example: How to sort pandas data frame using values from several columns?

I tried the solutions given by the users, bu

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 14:54

    By default pandas does not sort in place, unlike Python's list.

    Change

    maxTweets.sort_values(by=['Tweet', 'Retweets'], ascending=[False, True])
    

    to

    maxTweets = maxTweets.sort_values(by=['Tweet', 'Retweets'], ascending=[False, True])
    

    or pass inplace=True

    maxTweets.sort_values(by=['Tweet', 'Retweets'], ascending=[False, True], inplace=True)
    

提交回复
热议问题