Categorical用于将类别编码为数字类型
发布时间
阅读量:
阅读量
import pandas as pd
# 将类别转换为数字
cata = pd.Categorical(['c', 'b', 'a', 'a', 'd', 'd'])
# 获取原始数据中对应的数字下标,从0开始
print(cata.codes)
print(cata.categories)
[2 1 0 0 3 3]
Index([‘a’, ‘b’, ‘c’, ‘d’], dtype=‘object’)
全部评论 (0)
还没有任何评论哟~
