尝试对公司销售额从最大到最小进行排序,同时根据列表中的销售额索引重新排列公司名称。
我不知道该尝试什么,因为我陷入困境。
df=df.groupby(df['Distributor'])['Tickets Sold'].sum()
df1=df[df.div(df.sum()).lt(0.01)] df2=df.drop(df1.index)
yourdf=pd.concat([df2,pd.Series(df1.sum(),index=['Others'])])
print(yourdf)
而不是这个。
20th Century Fox 141367982
Focus Features 18799261
Lionsgate 75834308
Paramount Pictures 86302817
STX Entertainment 22606674
Sony Pictures 102746480
Universal 159556790
Walt Disney 315655340
Warner Bros. 216426845
Others 74618013
我需要这个。
Walt Disney 315655340
Warner Bros. 216426845
Universal 159556790
20th Century Fox 141367982
Sony Pictures 102746480
Paramount Pictures 86302817
Lionsgate 75834308
Others 74618013
STX Entertainment 22606674
Focus Features 18799261
最佳答案
您可以使用 sort_values() 方法
df.sort_values(by=['ColName'], ascending=False)
关于python - 使用 pandas group by 从最大到最小的顺序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55941941/