Pandas ordered categorical data on exam grades 'D',…,'A+'
问题 I have the following data in pandas, I was surprized that the output was: D+ A I was expecting A+ D can someone explain please df = pd.DataFrame(['A+','A','A-','B+','B','B-','C+','C','C-','D+','D'], index = ['excellent','excellent','excellent','good','good','good','ok','ok','ok','poor','poor']) df.rename (columns={0:'Grades'},inplace=True) grades = df['Grades'].astype('category', categories = ['D','D+', 'C-', 'C','C+','B-','B','B+','A-','A','A+'],ordered=True) print(max(grades),min(grades)) >