title: Set new reference-column after matching values
body: <p>i have problems finding a solution.</p>
  <p>lets assume i have the following input.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Identicator</th>
  <th>Description</th>
  <th>Value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>Acc1</td>
  <td>30</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Acc2</td>
  <td>40</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Acc3</td>
  <td>-70</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Acc4</td>
  <td>30</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Acc5</td>
  <td>30</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Acc2</td>
  <td>-60</td>
  </tr>
  <tr>
  <td>C</td>
  <td>Acc1</td>
  <td>15</td>
  </tr>
  <tr>
  <td>C</td>
  <td>Acc3</td>
  <td>-15</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc6</td>
  <td>50</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc2</td>
  <td>-25</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc3</td>
  <td>10</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc8</td>
  <td>-60</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc1</td>
  <td>12</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc2</td>
  <td>13</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have a reference number (&quot;identicator&quot;) for purchases (&quot;value&quot;) and the accounts.
  Usually transactions can be netted ((A) Acc1 + Acc2 +Acc3 = 0).
  The problem is, that the reference number sometimes contains two or more transactions, making the original reference number not perfect.
  Thus i am thinking of creating a new index. The Output could be for example:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Identicator</th>
  <th>Description</th>
  <th>Value</th>
  <th>ReferenceNo</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>Acc1</td>
  <td>30</td>
  <td>1</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Acc2</td>
  <td>40</td>
  <td>1</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Acc3</td>
  <td>-70</td>
  <td>1</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Acc4</td>
  <td>30</td>
  <td>2</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Acc5</td>
  <td>30</td>
  <td>2</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Acc2</td>
  <td>-60</td>
  <td>2</td>
  </tr>
  <tr>
  <td>C</td>
  <td>Acc1</td>
  <td>15</td>
  <td>3</td>
  </tr>
  <tr>
  <td>C</td>
  <td>Acc3</td>
  <td>-15</td>
  <td>3</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc6</td>
  <td>50</td>
  <td>4</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc2</td>
  <td>-25</td>
  <td>5</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc3</td>
  <td>10</td>
  <td>4</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc8</td>
  <td>-60</td>
  <td>4</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc1</td>
  <td>12</td>
  <td>5</td>
  </tr>
  <tr>
  <td>D</td>
  <td>Acc9</td>
  <td>13</td>
  <td>5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I am thinking hours how to do it but i feel this is just beyond my capabilities.</p>
  <p>Can anybody give me a hint?</p>
  <p>Edit1:
  The values are not in order.
  there is sometimes more than a negative value. For example it could also be -10,-40, +50 = 0</p>
  <p>Edit2:
  I don't want to simply pass on my fantasies, but I also don't want to mislead anyone. I was thinking about whether it would work via iterating through groups (itertools.groupby():) to achieve f.e. a isolated view of reference A and then over &quot;trial and error&quot; with for loops. But... don't know.</p>