12345678910import pandas as pdimport numpy as np# 创建待排序dataframename = ['Tom', 'John', 'Lillian']grade = [97,83,89]df_grade = pd.DataFrame(name,columns=['name'])df_grade['grade'] = pd.DataFrame(grade)# 指定排列顺序 e.g.按姓名排序sort_list = ['Lillian', 'Tom', 'John']df_grade123df_grade.index = df_grade['name']sort_df_grade = df_grade.loc[sort_list]sort_df_grade1234sort_list = ['a','b','c','d','e']data_merge['类'] = data_merge['品类'].astype('category')data_merge['类'].cat.reorder_categories(sort_list, inplace=True)data_merge.sort_values('类',inplace = True)