title: Pandas - KeyError: 'cannot use a single bool to index into setitem'
body: <p>I have written the following function. When calling it, it throws KeyError for <code>dataset.loc[]</code> call. I would like to understand why this is happening and how to avoid the same.</p>
  
  <pre><code>def ChangeColumnValues(dataset, columnValues):
      """Changes the values of given columns into the given key value pairs
  
      :: Argument Description ::
      dataset - Dataset for which the values are to be updated
      columnValues - Dictionary with Column and Value-Replacement pair
      """
  
      for column, valuePair in columnValues.items():
          for value, replacement in valuePair.items():
              dataset.loc[str(dataset[column]) == value, column] = replacement
  
      return dataset
  
  BankDS = da.ChangeColumnValues(BankDS, {
      'Default': {
          'no': -1,
          'yes': 1
      },
      'Housing': {
          'no': -1,
          'yes': 1
      },
      'Loan': {
          'no': -1,
          'yes': 1
      },
      'Y': {
          'no': 0,
          'yes': 1
      }
  })
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>---------------------------------------------------------------------------
  KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-20-0c766179be88&gt; in &lt;module&gt;()
       30     WineQualityDS = da.MeanNormalize(WineQualityDS)
       31 
  ---&gt; 32 PreProcessDataSets()
  
  &lt;ipython-input-20-0c766179be88&gt; in PreProcessDataSets()
       20         'Y': {
       21             'no': 0,
  ---&gt; 22             'yes': 1
       23         }
       24     })
  
  W:\MyProjects\Python\ML\FirstOne\DAHelper\DataSet.py in ChangeColumnValues(dataset, columnValues)
       73     for column, valuePair in columnValues.items():
       74         for value, replacement in valuePair.items():
  ---&gt; 75             dataset.loc[str(dataset[column]) == value, column] = replacement
       76 
       77     return dataset
  
  C:\Program Files\Anaconda3\lib\site-packages\pandas\core\indexing.py in __setitem__(self, key, value)
      177             key = com._apply_if_callable(key, self.obj)
      178         indexer = self._get_setitem_indexer(key)
  --&gt; 179         self._setitem_with_indexer(indexer, value)
      180 
      181     def _has_valid_type(self, k, axis):
  
  C:\Program Files\Anaconda3\lib\site-packages\pandas\core\indexing.py in _setitem_with_indexer(self, indexer, value)
      310                     # reindex the axis to the new value
      311                     # and set inplace
  --&gt; 312                     key, _ = convert_missing_indexer(idx)
      313 
      314                     # if this is the items axes, then take the main missing
  
  C:\Program Files\Anaconda3\lib\site-packages\pandas\core\indexing.py in convert_missing_indexer(indexer)
     1963 
     1964         if isinstance(indexer, bool):
  -&gt; 1965             raise KeyError("cannot use a single bool to index into setitem")
     1966         return indexer, True
     1967 
  
  KeyError: 'cannot use a single bool to index into setitem'
  </code></pre>
  
  <p>Also please let me know if there any better/right way to implement what I am trying achieve with ChangeColumnValues function</p>