title: Factorize values across dataframe columns with consistent mappings
body: <p>How can I use pandas <code>factorize</code> with values that exist across two columns? </p>
  
  <p>Specifically, I am trying to convert values that exist in two columns to numeric values, and put the corresponding factorized values into new columns, such that the factorization is consistent with the two input columns 'A' and 'B'.</p>
  
  <p>Existing DataFrame:</p>
  
  <pre><code>     A   B
  0    a   b
  1    c   a
  2    d   a
  3    e   c
  4    c   b
  5    b   e
  6    e   f
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>     A   B   A_ID  B_ID 
  0    a   b     0     4
  1    c   a     1     0
  2    d   a     2     0
  3    e   c     3     1
  4    c   b     1     4
  5    b   e     4     3
  6    e   f     3     5
  </code></pre>
  
  <p>I am able to use <code>factorize</code> successfully for one column using:</p>
  
  <pre><code>df['A_ID'] = pd.factorize(df.A)[0]
  </code></pre>
  
  <p>How could I accomplish this with consistent mappings for values across two columns? Do I need to resort to using a custom <code>lambda</code> function instead, or is there a way to accomplish this with <code>factorize</code>?</p>