title: In Pandas, how to create a unique ID based on the combination of many columns?
body: <p>I have a very large dataset, that looks like</p>
  
  <pre><code>df = pd.DataFrame({'B': ['john smith', 'john doe', 'adam smith', 'john doe', np.nan], 'C': ['indiana jones', 'duck mc duck', 'batman','duck mc duck',np.nan]})
  
  df
  Out[173]: 
              B              C
  0  john smith  indiana jones
  1    john doe   duck mc duck
  2  adam smith         batman
  3    john doe   duck mc duck
  4         NaN            NaN
  </code></pre>
  
  <p>I need to create a ID variable, that is unique for every B-C combination. That is, the output should be </p>
  
  <pre><code>            B              C   ID
  0  john smith  indiana jones   1
  1    john doe   duck mc duck   2
  2  adam smith         batman   3
  3    john doe   duck mc duck   2 
  4         NaN            NaN   0
  </code></pre>
  
  <p>I actually dont care about whether the index starts at zero or not, and whether the value for the missing columns is 0 or any other number. I just want something fast, that does not take a lot of memory and can be sorted quickly.
  I use:</p>
  
  <pre><code>df['combined_id']=(df.B+df.C).rank(method='dense')
  </code></pre>
  
  <p>but the output is <code>float64</code> and takes a lot of memory. Can we do better?
  Thanks!</p>