按值对Pandas DataFrame排序 [英] Sort Pandas DataFrame by value
本文介绍了按值对Pandas DataFrame排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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, but I cannot get a sorted column.
我建立了一个DataFrame:
I built a DataFrame:
weekly = {'Tweet ID': Series(tweetID),
'Fecha de Publicación': Series(tweetDate),
'Tweet': Series(textStatus),
'Retweets': Series(retweetCount),
'Favoritos': Series(favoriteCount),
'Hashtags': Series(hashtags),
'Menciones': Series(mentions)}
weeklyAnalysis = DataFrame(weekly)
然后我呼吁特定的推文:
Then I call for specific tweets:
maxTweets = weeklyAnalysis[['Tweet', 'Retweets']]
[weeklyAnalysis['Retweets'] >= promedioRts]
这是我尝试过的操作,以便对转发列进行排序:
This is what I tried, in order to sort retweets column:
maxTweets.sort_values(by=['Tweet', 'Retweets'], ascending=[False, True])
我该如何对 retweets 列进行排序.
How can I actually sort that retweets column.
任何建议,我们感激不尽!谢谢
Any suggestions are appreciated! Thanks
推荐答案
如果我对您的理解正确,那么您是否正在尝试通过转发"对df进行排序?使用:
If I'm understanding you correctly, you're trying to sort that df by 'retweets'? use:
maxTweets_sorted = maxTweets.sort_values(by='Retweets')
这篇关于按值对Pandas DataFrame排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文