2017-04-04 56 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

一小片段展示瞭如何會很好。 –