エラーの原因特定に時間かかりハマったので、自分用の備忘録。
ValueError: incompatible categories in categorical concat
本に書いてある通りに記述して実行するとエラーが発生した。
タイプミスが無いか何度も目視確認したが原因特定に時間かかりハマった。。
example.py
# カラム名を変更
train = train.rename(columns = {'train_id':'id'})
test = test.rename(columns = {'test_id':'id'})
# 両方のセットへカラムを追加
train['is_train'] = 1
test['is_train'] = 0
# trainのitem以外のデータをtestと連結
train_test_combine = pd.concat([train.drop(['item'], axis=1),test],axis=0)
# データ表示
train_test_combine.head()
を実行すると
terminal
ValueError: incompatible categories in categorical concat
とエラーが出る。
Pandasをアップデートして解決
パッケージが古いバージョン(0.18.1)だったので最新バージョン(0.22.0)にした。
$ pip list -o
:
numpy (1.12.1) - Latest: 1.14.0 [wheel]
oauth2client (3.0.0) - Latest: 4.1.2 [wheel]
openpyxl (2.3.2) - Latest: 2.5.0 [sdist]
pandas (0.18.1) - Latest: 0.22.0 [wheel]
partd (0.3.6) - Latest: 0.3.8 [wheel]
path.py (0.0.0) - Latest: 10.5 [wheel]
:
$ pip install -U pandas
Collecting pandas
Downloading pandas-0.22.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (14.9MB)
100% |████████████████████████████████| 14.9MB 53kB/s
Collecting python-dateutil>=2 (from pandas)
Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
100% |████████████████████████████████| 194kB 2.8MB/s
Collecting numpy>=1.9.0 (from pandas)
Downloading numpy-1.14.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.7MB)
100% |████████████████████████████████| 4.7MB 165kB/s
Collecting pytz>=2011k (from pandas)
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
100% |████████████████████████████████| 512kB 1.4MB/s
Collecting six>=1.5 (from python-dateutil>=2->pandas)
Downloading six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, numpy, pytz, pandas
Found existing installation: six 1.10.0
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.10.0:
Successfully uninstalled six-1.10.0
Found existing installation: python-dateutil 2.5.3
Uninstalling python-dateutil-2.5.3:
Successfully uninstalled python-dateutil-2.5.3
Found existing installation: numpy 1.12.1
Uninstalling numpy-1.12.1:
Successfully uninstalled numpy-1.12.1
Found existing installation: pytz 2016.6.1
DEPRECATION: Uninstalling a distutils installed project (pytz) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling pytz-2016.6.1:
Successfully uninstalled pytz-2016.6.1
Found existing installation: pandas 0.18.1
Uninstalling pandas-0.18.1:
Successfully uninstalled pandas-0.18.1
Successfully installed numpy-1.14.0 pandas-0.22.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0
[参考] Stack Overflow
ValueError: incompatible categories in categorical concat
https://stackoverflow.com/questions/41386520/valueerror-incompatible-categories-in-categorical-concat