title: TypeError while mapping DataFrame Columns using Python dict
body: <p>I try to translate a column of a Pandas Data Frame into int values using a mapping like this (asuming a given dataframe: my_dataframe and a colum: target_column):</p>
  
  <pre><code>targets = my_dataframe[target_column].unique()
  map_to_int = {name: n  for n, name in enumerate(targets)}
  </code></pre>
  
  <p>Using Python 3.6 with Pandas I wonder why</p>
  
  <p>A)</p>
  
  <pre><code>my_dataframe['Integer-Column'] = map_to_int[my_dataframe[target_column]]
  </code></pre>
  
  <p>causes a </p>
  
  <blockquote>
    <p>TypeError: 'Series' objects are mutable, thus they cannot be hashed</p>
  </blockquote>
  
  <p>whileas </p>
  
  <p>B)</p>
  
  <pre><code>my_dataframe['Integer-Column'] = my_dataframe[target_column].replace(map_to_int)
  </code></pre>
  
  <p>works fine.</p>
  
  <p>I would like to understand why this happens. Is there any magic in replace that the TypeError is not thrown or am I missing something else? I already got the fact, that dict-keys are not allowed to be changeable. But still I have a hard time understanding this for real, since:</p>
  
  <pre><code>    words = my_dataframe[target_column].unique()
      # words = ['car' 'bike' 'plain']
  
      foo = 'car'
      map_to_int[foo] = 0
      foo = 'bike'
      map_to_int["bike"] = 1
  </code></pre>
  
  <p>Any attempt to help me understand why B) works without the trouble of A) would be appreciated.</p>