title: pandas get mapping of categories to integer value
body: <p>I can transform categorical columns to their categorical code but how do i get an accurate picture of their mapping?  Example:</p>
  
  <pre><code>df_labels = pd.DataFrame({'col1':[1,2,3,4,5], 'col2':list('abcab')})
  df_labels['col2'] = df_labels['col2'].astype('category')  
  </code></pre>
  
  <p>df_labels looks like this:</p>
  
  <pre><code>   col1 col2
  0     1    a
  1     2    b
  2     3    c
  3     4    a
  4     5    b
  </code></pre>
  
  <p>How do i get an accurate mapping of the cat codes to cat categories?
  The stackoverflow response below says to enumerate the categories. However, I'm not sure if enumerating was the way cat.codes generated the integer values. Is there a more accurate way?</p>
  
  <p><a href="https://stackoverflow.com/questions/30510562/get-mapping-of-categorical-variables-in-pandas">Get mapping of categorical variables in pandas</a></p>
  
  <pre><code>&gt;&gt;&gt; dict( enumerate(df.five.cat.categories) )
  
  {0: 'bad', 1: 'good'}
  </code></pre>
  
  <p>What is a good way to get the mapping in the above format but accurate?</p>