title: Cumulative count in a pandas df
body: <p>I am trying to export a <code>cumulative</code> <code>count</code> based off two columns in a <code>pandas</code> <code>df</code>. </p>
  
  <p>An example is the <code>df</code> below. I'm trying to export a <code>count</code> based off <code>Value</code> and <code>Count</code>. So when the <code>count</code> increase I want attribute that to the adjacent <code>value</code></p>
  
  <pre><code>import pandas as pd
  
  d = ({
      'Value' : ['A','A','B','C','D','A','B','A'],
      'Count' : [0,1,1,2,3,3,4,5],
      }) 
  
  df = pd.DataFrame(d)
  </code></pre>
  
  <p>I have used this:</p>
  
  <pre><code>for val in ['A','B','C','D']:
      cond = df.Value.eq(val) &amp; df.Count.eq(int)
      df.loc[cond, 'Count_' + val] = cond[cond].cumsum()
  </code></pre>
  
  <p>If I alter <code>int</code> to a specific number it will return the count. But I need this to read any number as the <code>Count</code> column keeps increasing.</p>
  
  <p>My intended output is:</p>
  
  <pre><code>  Value  Count  A_Count  B_Count  C_Count  D_Count
  0     A      0        0        0        0        0
  1     A      1        1        0        0        0
  2     B      1        1        0        0        0
  3     C      2        1        0        1        0
  4     D      3        1        0        1        1
  5     A      3        1        0        1        1
  6     B      4        1        1        1        1
  7     A      5        2        1        1        1
  </code></pre>
  
  <p>So the <code>count</code> increase on the <code>second row</code> so <code>1</code> to <code>Value A</code>. <code>Count</code> increases again on <code>row 4</code> and it's the first time for <code>Value C</code> so <code>1</code>. Same again for <code>rows 5</code> and <code>7</code>. The <code>count</code> increases on <code>row 8</code> so <code>A</code> becomes <code>2</code>.</p>