--------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~/study/env3/local/lib/python3.5/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2441 try: -> 2442 return self._engine.get_loc(key) 2443 except KeyError: pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)() pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)() KeyError: 'D' During handling of the above exception, another exception occurred: KeyError Traceback (most recent call last) in () 5 enc = BinaryEncoder(handle_unknown='error') 6 enc.fit(data) ----> 7 enc.transform(data) ~/study/env3/local/lib/python3.5/site-packages/category_encoders/binary.py in transform(self, X) 155 return X 156 --> 157 X = self.ordinal_encoder.transform(X) 158 159 X = self.binary(X, cols=self.cols) ~/study/env3/local/lib/python3.5/site-packages/category_encoders/ordinal.py in transform(self, X) 173 cols=self.cols, 174 impute_missing=self.impute_missing, --> 175 handle_unknown=self.handle_unknown 176 ) 177 ~/study/env3/local/lib/python3.5/site-packages/category_encoders/ordinal.py in ordinal_encoding(X_in, mapping, cols, impute_missing, handle_unknown) 211 X[switch.get('col')].fillna(-1, inplace=True) 212 elif handle_unknown == 'error': --> 213 if X[~X['D'].isin([str(x[1]) for x in switch.get('mapping')])].shape[0] > 0: 214 raise ValueError('Unexpected categories found in %s' % (switch.get('col'), )) 215 ~/study/env3/local/lib/python3.5/site-packages/pandas/core/frame.py in __getitem__(self, key) 1962 return self._getitem_multilevel(key) 1963 else: -> 1964 return self._getitem_column(key) 1965 1966 def _getitem_column(self, key): ~/study/env3/local/lib/python3.5/site-packages/pandas/core/frame.py in _getitem_column(self, key) 1969 # get column 1970 if self.columns.is_unique: -> 1971 return self._get_item_cache(key) 1972 1973 # duplicate columns & possible reduce dimensionality ~/study/env3/local/lib/python3.5/site-packages/pandas/core/generic.py in _get_item_cache(self, item) 1643 res = cache.get(item) 1644 if res is None: -> 1645 values = self._data.get(item) 1646 res = self._box_item_values(item, values) 1647 cache[item] = res ~/study/env3/local/lib/python3.5/site-packages/pandas/core/internals.py in get(self, item, fastpath) 3588 3589 if not isnull(item): -> 3590 loc = self.items.get_loc(item) 3591 else: 3592 indexer = np.arange(len(self.items))[isnull(self.items)] ~/study/env3/local/lib/python3.5/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2442 return self._engine.get_loc(key) 2443 except KeyError: -> 2444 return self._engine.get_loc(self._maybe_cast_indexer(key)) 2445 2446 indexer = self.get_indexer([key], method=method, tolerance=tolerance) pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)() pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)() KeyError: 'D'