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)
每天扫一扫,到店付款省钱!
动动小手支持一下作者,谢谢🙏