title: Pandas groupby cumulative sum to threshold
body: <p>Using a groupby operation in Pandas, can the cumsum function be used to meet (or exceed by one record) a threshold?</p>
  
  <p>The Goal is to <em>at least meet or exceed</em> the threshold and then stop accumulating further. </p>
  
  <p><strong>Example dataframe:</strong></p>
  
  <pre><code>import pandas as pd
  
  data = [
  {'a':'z', 'b': 5, 'c': 15}, {'a':'z', 'b': 10, 'c': 15},
  'a':'z', 'b': 2, 'c': 15},
  {'a': 'x', 'b': 10, 'c':31}, {'a':'x', 'b': 20, 'c': 31}, {'a':'x',
  'b': 5, 'c': 31, {'a':'x', 'b': 9, 'c': 31}
  ] 
  df = pd.DataFrame(data) 
  
  df:
  
      a   b   c
  0   z   5   15
  1   z   10  15
  2   z   2   15
  3   x   10  31
  4   x   20  31
  5   x   5   31
  6   x   9   31
  </code></pre>
  
  <p>The only equation I can visualize doesn't meet or exceed the threshold for the X group: </p>
  
  <pre><code>df[df.groupby(by='a')['b'].cumsum()&lt;=df['c']] 
  
      a   b   c
  0   z   5   15
  1   z   10  15
  3   x   10  31
  4   x   20  31
  </code></pre>
  
  <p>It works for group z (ie, 5+10 = 15) but fails for group x b/c (ie, 10+20 &lt; 31). </p>
  
  <p>For group x, I need to meet (or exceed by one record) the value of 31. So the next record should also be accumulated (ie 10+20+5 >= 31 but note it stops accumulating any further (ie doesnt also take 9).</p>
  
  <p>Is there a way to apply an accumulative operation that will meet, or exceed by a single record, a benchmark? </p>
  
  <p><strong>Expected/Desired Outcome:</strong></p>
  
  <pre><code>    a   b   c
  0   z   5   15
  1   z   10  15
  3   x   10  31
  4   x   20  31
  5   x   5   31
  </code></pre>