title: Python pandas cumsum with reset everytime there is a 0
body: <p>I have a matrix with 0s and 1s, and want to do a cumsum on each column that resets to 0 whenever a zero is observed. For example, if we have the following:</p>
  
  <pre><code>df = pd.DataFrame([[0,1],[1,1],[0,1],[1,0],[1,1],[0,1]],columns = ['a','b'])
  print(df)
     a  b
  0  0  1
  1  1  1
  2  0  1
  3  1  0
  4  1  1
  5  0  1
  </code></pre>
  
  <p><strong>The result I desire is:</strong></p>
  
  <pre><code>print(df)
     a  b
  0  0  1
  1  1  2
  2  0  3
  3  1  0
  4  2  1
  5  0  2
  </code></pre>
  
  <p>However, when I try <code>df.cumsum() * df</code>, I am able to correctly identify the 0 elements, but the counter does not reset:</p>
  
  <pre><code>print(df.cumsum() * df)
     a  b
  0  0  1
  1  1  2
  2  0  3
  3  2  0
  4  3  4
  5  0  5
  </code></pre>