pandas 多列排序

import pandas as pd
df = pd.DataFrame({'AAA' : [1,2,1,3], 'BBB' : [1,1,2,2], 'CCC' : [2,1,3,1]})
source_cols = df.columns
new_cols = [str(x) + "_cat" for x in source_cols]
categories = {1 : 'Alpha', 2 : 'Beta', 3 : 'Charlie' }
df[new_cols] = df[source_cols].applymap(categories.get)
df.sort_values(['AAA_cat','BBB_cat'],ascending=[0,1],inplace=True)

  

 

posted on 2018-12-10 15:13  hailuo  阅读(5205)  评论(0编辑  收藏  举报