title: How can I perform an addition on a column based on a condition which changes per row?
body: <p>I have a data handling question that I hope someone could help with.</p>
  
  <p>I have two columns in a dataframe:</p>
  
  <pre><code>A               B
  111            5.2
  EF             5.6
  DG             5.1
  LK             5.4
  111            5
  EF             5.2
  </code></pre>
  
  <p>I want to make a 3rd column C where everytime 111 is shown in column a, I want to take the difference from 5 away from Column B until the next 111 is shown.</p>
  
  <p>So it would look like this</p>
  
  <pre><code>A               B            C
  111            5.2         5 (minus 0.2)
  EF             5.6         5.4 (minus 0.2)
  DG             5.1         4.9 (minus 0.2
  LK             5.4         5.2 (minus 0.2)
  111            5            5 (no change needed as already 5)
  EF             5.2          5.2 (no change needed as previous 111 already 5)
  </code></pre>
  
  <p>So if 111 in column A has a value in Column B of 5.2 then (5-5.2=-0.2) Therefore C=5.2 + -0.2 = 5
  If 111 in Column A has a value in Column B of 4.8 then (5-4.8=0.2) Therefore C=4.8+0.2 = 5
  Etc until the next 111 is found.</p>
  
  <p>Hopefully this makes sense. Essentially 111 is a standard that should be 5. If it is not 5 then I want to apply the difference to all over values in Row B until a new 111 is found.
  Any suggestions regarding this?</p>