我想重命名类别并将缺少的类别添加到系列。重命名类别并将缺失的类别添加到系列PANDAS
我的代码:
codedCol = bdAu['Bordersite']
print 'pre:'
print codedCol.head(10)
codedCol = codedCol.astype('category')
codedCol = codedCol.cat.set_categories(['a','b','c','d','e','f','g','h','i','j'])
print 'post:'
print codedCol.head(10)
当我这样做,我得到结果为NaN。
pre:
0 3
1 3
2 2
3 2
4 3
5 4
6 5
7 3
8 3
9 3
Name: Bordersite, dtype: int64
post:
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
7 NaN
8 NaN
9 NaN
dtype: category
Categories (10, object): [a, b, c, d, ..., g, h, i, j]
我在这里做错了什么?
感谢 Kheeran
什么是你理想的结果? –
我已经添加了一个答案...让我知道它是否有帮助。 –