数据框看起来像
Names Rank
Michael 8
David 6
Christopher 6
Brian 5
Amanda 3
Heather 8
Sarah 2
Rebecca 4
Expected O/P
Names Rank
Heather 8
Michael 8
Christopher 6
David 6
Brian 5
Rebecca 4
Amanda 3
Sarah 2
在这里,我需要先按降序对 rank 列进行排序,然后按字母顺序对 Name 列进行排序。
我的代码:
df = df.sort_values(['Name'],ascending = True)
df = df.'Name'.sort_values(['Rank'],ascending = False)
df
这段代码给了我排序的排名,但 Name 列没有排序。
df = df.sort_values(['Rank', 'Name'],ascending = [False, True])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句