title: Python Pandas Add DataRow Revision Number
body: <p>I have a Data Frame looking like below. I need to use a combination of ID and Serial and calculate revision numbers.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>Serial</th>
  <th>Time</th>
  <th>Revision</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>12/31/2020 8:37:13 AM</td>
  <td></td>
  </tr>
  <tr>
  <td>78faedd8-a250-4e52-ac81-a29d46715a51</td>
  <td>PQR</td>
  <td>12/03/2019 1:30:00 AM</td>
  <td></td>
  </tr>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>12/31/2020 8:37:13 AM</td>
  <td></td>
  </tr>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>01/23/2021 5:18:44 PM</td>
  <td></td>
  </tr>
  <tr>
  <td>78faedd8-a250-4e52-ac81-a29d46715a51</td>
  <td>ABC</td>
  <td>10/23/2020 8:01:08 AM</td>
  <td></td>
  </tr>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>01/20/2021 8:10:27 PM</td>
  <td></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>Expected result:</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>Serial</th>
  <th>Time</th>
  <th>Revision</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>12/31/2020 8:37:13 AM</td>
  <td>1</td>
  </tr>
  <tr>
  <td>78faedd8-a250-4e52-ac81-a29d46715a51</td>
  <td>PQR</td>
  <td>12/03/2019 1:30:00 AM</td>
  <td>1</td>
  </tr>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>12/31/2020 8:37:13 AM</td>
  <td>1</td>
  </tr>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>01/23/2021 5:18:44 PM</td>
  <td>3</td>
  </tr>
  <tr>
  <td>78faedd8-a250-4e52-ac81-a29d46715a51</td>
  <td>ABC</td>
  <td>10/23/2020 8:01:08 AM</td>
  <td>1</td>
  </tr>
  <tr>
  <td>48ff35eb-70ad-4dcd-a441-8c7c9966a236</td>
  <td>ABC</td>
  <td>01/20/2021 8:10:27 PM</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I tried the following:</p>
  <pre><code>columns_of_interest = [&quot;ID&quot;, &quot;Serial&quot;]
  df[&quot;revision&quot;] = df.groupby(columns_of_interest).cumcount() + 1
  </code></pre>
  <p>Then, I just got the row counts for each group, but how I do get accurate version numbers?</p>