title: pandas ValueError: Cannot setitem on a Categorical with a new category, set the categories first
body: <p>Now, I am changing the information inside DataFrame by replacing Yes with 1 and No with 0. Previously, my code worked fine and now I made some changes due to a memory problem.</p>
  <p><strong>Previous code</strong> &quot;Got Traceback Error mentioned below&quot;</p>
  <pre><code>df.loc[df[df.decision == 'Yes'].index, 'decision'] = 1
  df.loc[df[df.decision == 'No'].index, 'decision'] = 0
  </code></pre>
  <p><strong>Changed with</strong></p>
  <pre><code>df.loc['Yes', &quot;decision&quot;] = 1
  df.loc['No', &quot;decision&quot;] = 0
  </code></pre>
  <p>Still, the problem remains the same.</p>
  <p><strong>Traceback</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;/snap/pycharm-community/226/plugins/python-ce/helpers/pydev/pydevd.py&quot;, line 1477, in _exec
      pydev_imports.execfile(file, globals, locals)  # execute the script
    File &quot;/snap/pycharm-community/226/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py&quot;, line 18, in execfile
      exec(compile(contents+&quot;\n&quot;, file, 'exec'), glob, loc)
    File &quot;/home/khawar/deepface/tests/Ensemble-Face-Recognition.py&quot;, line 148, in &lt;module&gt;
      df.loc['Yes', &quot;decision&quot;] = 1
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/indexing.py&quot;, line 670, in __setitem__
      iloc._setitem_with_indexer(indexer, value)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/indexing.py&quot;, line 1763, in _setitem_with_indexer
      isetter(loc, value)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/indexing.py&quot;, line 1689, in isetter
      ser._mgr = ser._mgr.setitem(indexer=plane_indexer, value=v)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/internals/managers.py&quot;, line 543, in setitem
      return self.apply(&quot;setitem&quot;, indexer=indexer, value=value)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/internals/managers.py&quot;, line 409, in apply
      applied = getattr(b, f)(**kwargs)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/internals/blocks.py&quot;, line 1688, in setitem
      self.values[indexer] = value
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/pandas/core/arrays/categorical.py&quot;, line 2011, in __setitem__
      &quot;Cannot setitem on a Categorical with a new &quot;
  ValueError: Cannot setitem on a Categorical with a new category, set the categories first
  python-BaseException
  </code></pre>
  <p><strong>As suggested I implemented new code</strong></p>
  <pre><code>df['decision'] = (df['decision'] == 'Yes').astype(int)
  </code></pre>
  <p><strong>Traceback</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;/home/khawar/deepface/tests/Ensemble-Face-Recognition.py&quot;, line 174, in &lt;module&gt;
      gbm = lgb.train(params, lgb_train, num_boost_round=1000, early_stopping_rounds=15, valid_sets=lgb_test)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/lightgbm/engine.py&quot;, line 231, in train
      booster = Booster(params=params, train_set=train_set)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/lightgbm/basic.py&quot;, line 2053, in __init__
      train_set.construct()
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/lightgbm/basic.py&quot;, line 1325, in construct
      categorical_feature=self.categorical_feature, params=self.params)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/lightgbm/basic.py&quot;, line 1123, in _lazy_init
      self.__init_from_np2d(data, params_str, ref_dataset)
    File &quot;/home/khawar/.local/lib/python3.6/site-packages/lightgbm/basic.py&quot;, line 1162, in __init_from_np2d
      data = np.array(mat.reshape(mat.size), dtype=np.float32)
  ValueError: could not convert string to float: 'deepface/tests/dataset/029A33.JPG'
  </code></pre>