我正在尝试为Pandas中的mergecats寻找等效的Pandas:https://uk.mathworks.com/help/matlab/ref/categorical.mergecats.html
import numpy as np
import pandas as pd
student_scores=pd.DataFrame(
[['Philip',80],
['Jess', 65],
['Maya',70],
['Jordan',54],
['John',38],
['Roisin',40],
['Petra',35],
['Lisa',69],
['Simon',55],
['Peter',70]],
index=[0,1,2,3,4,5,6,7,8,9],
columns=['Student','Score']
)
student_scores['Selected_Slices']=pd.cut(student_scores.Score, bins=[0,50,60,70,80,100])
student_scores=student_scores.rename(columns={'Selected_Slices':'Grades'})
student_scores.Grades.cat.categories=['F','D','C','B','A']
# Yields an Error
student_scores.Grades.cat.rename_categories(['Fail','Pass','Pass','Pass','Pass'])
# ValueError: Categorical categories must be unique
rename_categories或set_categories产生错误: ValueError:分类类别必须是唯一的