title: Map unique values in 2 columns to integers
body: <p>I have a dataframe with 2 categorical columns (col1, col2).</p>
  <pre class="lang-py prettyprint-override"><code>  col1 col2
  0    A   DE
  1    A    B
  2    B   BA
  3    A    A
  4    C    C 
  </code></pre>
  <p>I want to map the unique string values to integers, for example (A:0, B:1, BA:2, C:3, DE:4)</p>
  <pre class="lang-py prettyprint-override"><code>  col1 col2  ideal1  ideal2
  0    A   DE       0       4
  1    A    B       0       1
  2    B   BA       1       2
  3    A    A       0       0
  4    C    C       3       3
  </code></pre>
  <p>I am have tried to use factorize or category, but I am <strong>not getting the same unique value for both columns</strong>, as can be seen from ROW C:</p>
  <p>Here is my code:</p>
  <pre class="lang-py prettyprint-override"><code>df = pd.DataFrame({'col1': [&quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;A&quot; , &quot;C&quot;], 'col2': [&quot;DE&quot;, &quot;B&quot;, &quot;BA&quot;, &quot;A&quot;, &quot;C&quot;]}) 
  
  #ideal map alphabetical: A:0, B:1, BA:2, C:3, DE:4
  
   #ideal result 
  df[&quot;ideal1&quot;] = [0, 0, 1,0, 3]
  df[&quot;ideal2&quot;] = [4,1,2,0,3]
  
  
   #trial #1 --&gt; C value 2 &amp; 3 : not matching
  df[&quot;cat1&quot;] = df['col1'].astype(&quot;category&quot;).cat.codes
  df[&quot;cat2&quot;] = df['col2'].astype(&quot;category&quot;).cat.codes
  
   #trial #2 --&gt; C value 2 &amp; 4 : not matching 
  df[&quot;fac1&quot;] = pd.factorize(df[&quot;col1&quot;])[0]
  df[&quot;fac2&quot;] = pd.factorize(df[&quot;col2&quot;])[0]
  
  
   
  print (df)
  
  OUT: 
  
    col1 col2  ideal1  ideal2  cat1  cat2  fac1  fac2
  0    A   DE       0       4     0     4     0     0
  1    A    B       0       1     0     1     0     1
  2    B   BA       1       2     1     2     1     2
  3    A    A       0       0     0     0     0     3
  4    C    C       3       3     2     3     2     4
  </code></pre>