title: Python - Perform a FIFO operation on data in Pandas DataFrame
body: <p>I have some data in Pandas that looks like this.</p>
  
  <pre><code>| DAY | IN  | OUT |
  |-----|-----|-----|
  |   1 | 100 |  50 |
  |   2 |  20 |  60 |
  |   3 |  10 |   5 |
  |   4 |   5 |  15 |
  </code></pre>
  
  <p>This represents the day an item went into a queue, and how many came out of the queue. When things go into the queue, I don't really have a way of tracking them so I assume that they are processed in order and you have a FIFO (first in, first out) type operation. </p>
  
  <p>What I want to do is perform a FIFO operation so I can see what how many days the operation took. So as an example... </p>
  
  <pre><code>| DAY | IN  | OUT |   1 |   2 |   3 |
  |-----|-----|-----|-----|-----|-----|
  |   1 | 100 |  50 |  50 |   0 |   0 |
  |   2 |  20 |  60 |  10 |  50 |   0 |
  |   3 |  10 |   5 |   0 |   5 |   0 |
  |   4 |   5 |  15 |   0 |  10 |   5 |
  </code></pre>
  
  <p>The last 3 columns I appended represent how many came out of the process in how many days. So said verbally...</p>
  
  <ul>
  <li>On day 1, 100 went in and 50 came out. Therefore, 50 were processed in 1 day and 50 remained in queue. </li>
  <li>On day 2, 20 went in and 60 came out. Therefore, the prior queue of 50 was exhausted and those took 2 days. The remaining 10 that came out completed in 1 day. 10 remained in queue. </li>
  <li>On day 3, 10 went in and 5 came out. Therefore, the prior queue of 10 was reduced to 5. Those 5 that came out were competed in 2 days. 15 remained in queue. </li>
  <li>On day 4, 5 went in and 15 came out. Therefore, the prior queue of 15 was exhausted. 5 took 3 days to complete and 10 took 2 days. 5 remained in queue.</li>
  <li>etc. </li>
  </ul>
  
  <p>Anyone have some code (or pseudocode) to do this in a pythonic way, preferably using Pandas? </p>