Sort Pandas DataFrame by value

前端 未结 2 1068
攒了一身酷
攒了一身酷 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:47

    If I'm understanding you correctly, you're trying to sort that df by 'retweets'? use:

    maxTweets_sorted = maxTweets.sort_values(by='Retweets')
    
    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题