Sort pandas dataframe both on values of a column and index?

后端 未结 8 1632
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 08:43

Is it feasible to sort pandas dataframe by values of a column, but also by index?

If you sort a pandas dataframe by values of a column, you can get the resultant dat

8条回答
  •  误落风尘
    2020-12-13 09:26

    I believe that the original order from sort_values is kept even when sort_index is applied, so this should work:

    df.sort_values('count', ascending=False).sort_index(level=[index_level1, index_level2])
    

提交回复
热议问题