title: Create a new column with unique identifier for each group
body: <p>I need to create a new &quot;identifier column&quot; with unique values for each combination of values of two columns. For example, the same &quot;identifier&quot; should be used when <strong>ID</strong> and <strong>phase</strong> are the same (e.g. r1 and ph1 [but a new, unique value should be added to the column when r1 and ph2])</p>
  <pre><code>df
  ID   phase   side   values
  r1   ph1     l      12
  r1   ph1     r      34
  r1   ph2     l      93
  s4   ph3     l      21
  s3   ph2     l      88
  s3   ph2     r      54
  ...
  </code></pre>
  <p>I would need a new column (idx) like so:</p>
  <pre><code>new_df
  ID   phase   side   values    idx
  r1   ph1     l      12        1
  r1   ph1     r      34        1
  r1   ph2     l      93        2
  s4   ph3     l      21        3
  s3   ph2     l      88        4
  s3   ph2     r      54        4
  ...
  </code></pre>
  <p>I've tried applying code from <a href="https://stackoverflow.com/questions/21702342/creating-a-new-column-based-on-if-elif-else-condition">this question</a> but could no achieve a way to increment the values in idx.</p>