pandas文字列列をCategoricalに変換できますが、新しいDataFrame列として挿入しようとすると、Seriesofstrに変換されて戻ってくるようです。
train['LocationNFactor'] = pd.Categorical.from_array(train['LocationNormalized'])
>>> type(pd.Categorical.from_array(train['LocationNormalized']))
<class 'pandas.core.categorical.Categorical'>
# however it got converted back to...
>>> type(train['LocationNFactor'][2])
<type 'str'>
>>> train['LocationNFactor'][2]
'Hampshire'
これを推測するのは、Categoricalがnumpydtypeにマップされないためです。それで、それをいくつかのint型に変換する必要があります。そのため、因子ラベル<->レベルの関連付けが失われますか?レベル<->ラベルの関連付けを保存し、元に戻す機能を保持するための最も洗練された回避策は何ですか?(ここのようにdictとして保存し、必要に応じて手動で変換しますか?) Rとは異なり、CategoricalはまだDataFrameのファーストクラスのデータ型ではないと思います。
(pandas 0.10.1、numpy 1.6.2、python 2.7.3を使用-すべての最新のmacportsバージョン)。