title: Map dictionary values in Pandas
body: <p>I have a data frame (<code>df</code>) with the following:</p>
  
  <pre><code> var1
  a 1 
  a 1 
  b 2  
  b 3 
  c 3 
  d 5 
  </code></pre>
  
  <p>And a dictionary: </p>
  
  <pre><code>dict_cat = {
  'x' = ['a', 'b', 'c'],
  'y' = 'd' }
  </code></pre>
  
  <p>And I want to create a new column called <code>cat</code> in which depending of the <code>var1</code> value, it takes the dict key value:</p>
  
  <pre><code> var1 cat
  a 1 x 
  a 1 x
  b 2 x
  b 3 x
  c 3 x
  d 5 y
  </code></pre>
  
  <p>I have tried to <code>map</code> the dict to the variable using: <code>df['cat'] = df['var1'].map(dict_cat)</code>, but since values are inside a list, Python do not recognize the values and I only get <code>NaN</code> values. There is a way to do this using <code>map</code>, or should I create a function that iterates over rows checking if <code>var1</code> is <code>in</code> the dictionary lists?</p>
  
  <p>Thanks!</p>