title: Convert multiple columns of a pandas data frame to dummy variables - Python
body: <p>I have this dataframe:</p>
  
  <p><img src="https://i.stack.imgur.com/QPPgm.jpg" alt="enter image description here"></p>
  
  <p>As far as I know, to use the scikit learn package in Python for machine leaning tasks, the categorical variables should be converted to dummy variables. So, for example, using a library of  scikit learn I try to convert the values of the third column to dummy values but my code didn't work:</p>
  
  <pre><code>from sklearn.preprocessing import LabelEncoder
  
  x[:, 2] = LabelEncoder().fit_transform(x[:,2])
  </code></pre>
  
  <p>So what's wrong with my code? and How Can I convert all the categorical variables to dummy variables in my data frame?</p>
  
  <p>Edit: The full traceback is this :</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-73-c0d726db979e&gt; in &lt;module&gt;()
        1 from sklearn.preprocessing import LabelEncoder
        2 
  ----&gt; 3 x[:, 2] = LabelEncoder().fit_transform(x[:,2])
  
  C:\Users\toshiba\Anaconda\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key)
     2001             # get column
     2002             if self.columns.is_unique:
  -&gt; 2003                 return self._get_item_cache(key)
     2004 
     2005             # duplicate columns
  
  C:\Users\toshiba\Anaconda\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item)
      665             return cache[item]
      666         except Exception:
  --&gt; 667             values = self._data.get(item)
      668             res = self._box_item_values(item, values)
      669             cache[item] = res
  
  C:\Users\toshiba\Anaconda\lib\site-packages\pandas\core\internals.pyc in get(self, item)
     1653     def get(self, item):
     1654         if self.items.is_unique:
  -&gt; 1655             _, block = self._find_block(item)
     1656             return block.get(item)
     1657         else:
  
  C:\Users\toshiba\Anaconda\lib\site-packages\pandas\core\internals.pyc in _find_block(self, item)
     1933 
     1934     def _find_block(self, item):
  -&gt; 1935         self._check_have(item)
     1936         for i, block in enumerate(self.blocks):
     1937             if item in block:
  
  C:\Users\toshiba\Anaconda\lib\site-packages\pandas\core\internals.pyc in _check_have(self, item)
     1939 
     1940     def _check_have(self, item):
  -&gt; 1941         if item not in self.items:
     1942             raise KeyError('no item named %s' % com.pprint_thing(item))
     1943 
  
  C:\Users\toshiba\Anaconda\lib\site-packages\pandas\core\index.pyc in __contains__(self, key)
      317 
      318     def __contains__(self, key):
  --&gt; 319         hash(key)
      320         # work around some kind of odd cython bug
      321         try:
  
  TypeError: unhashable type
  </code></pre>