pandas中的categorical类型 对象属性生成方法将dataframe的一列转换为categorical对象其他序列直接生成利用分类编码数据生成 使用Categorical对象进行计算 对象 属性 categoriescodes 生成方法 将dataframe的一列转换为categorical对象 df[name] = df[name].astype('category') 其他序列直接生成 pd.Categorical(list) 利用分类编码数据生成 categories = ['a', 'b', 'c'] codes = [0, 1, 2, 0, 0, 2, 1] ca = pd.Categorical.from_codes(codes, categories) 使用Categorical对象进行计算