2017-04-04 70 views
1

熊猫数据框有一种方式来将数据作为整数存储在列中,但是当我在屏幕上将其打印出来以显示相应的标签时。存储int显示标签?枚举

有点像枚举映射INT < =>标签的

+4

我认为你可以使用[类别数据](https://pandas-docs.github.io/pandas-docs-travis/categorical.html) – MaxU

回答

1

分类数据将做的工作。感谢

df = pd.DataFrame({"A" : ['c', 'b','f', 'e']}) 
df.A.astype('category') 
df.A.cat.categories 
Index([u'b', u'c', u'e', u'f'], dtype='object') 

df.A.cat.codes 

0 1 
1 0 
2 3 
3 2 
dtype: int8 

memory usage

+0

一小片段展示了如何会很好。 –