title: Get cumulative sum Pandas conditional on other column
body: <p>I want to create a column that shows the cumulative count (rolling sum) of previous purchases (per customer) that took place in department 99</p>
  
  <p>My data frame looks like this ; where each row is a separate transaction.  </p>
  
  <pre><code>    id  chain   dept    category    company     brand   date    productsize     productmeasure  purchasequantity    purchaseamount  sale
  0   86246   205     7   707     1078778070  12564   2012-03-02  12.00   OZ  1   7.59    268.90
  1   86246   205     63  6319    107654575   17876   2012-03-02  64.00   OZ  1   1.59    268.90
  2   86246   205     97  9753    1022027929  0   2012-03-02  1.00    CT  1   5.99    268.90
  3   86246   205     25  2509    107996777   31373   2012-03-02  16.00   OZ  1   1.99    268.90
  4   86246   205     55  5555    107684070   32094   2012-03-02  16.00   OZ  2   10.38   268.90
  5   86246   205     97  9753    1021015020  0   2012-03-02  1.00    CT  1   7.80    268.90
  6   86246   205     99  9909    104538848   15343   2012-03-02  16.00   OZ  1   2.49    268.90
  7   86246   205     59  5907    102900020   2012    2012-03-02  16.00   OZ  1   1.39    268.90
  8   86246   205     9   921     101128414   9209    2012-03-02  4.00    OZ  2   1.50    268.90
  </code></pre>
  
  <p>I did this : </p>
  
  <pre><code>
  shopdata6['transactions_99'] = 0
  shopdata6['transactions_99'] = shopdata6[shopdata6['dept'] == 99].groupby(['id', 'dept'])['transaction_99'].cumsum()
  </code></pre>
  
  <p>Update : </p>
  
  <pre><code>id dept  date   purchase purchase_count_dept99(desired)
  
  id1 199  date1  $10       0    
  
  id1 99  date1  $10       1
  
  id1 100 date1  $50       1
  
  id1 99  date2  $30       2
  
  id2 100 date1  $10       0
  
  id2 99  date1  $10       1
  
  id3 99 date3  $10        1
  </code></pre>
  
  <p>Applied this :</p>
  
  <pre><code>shopdata6['transaction_99'] = np.where(shopdata6['dept']==99, 1, 0)
  shopdata6['transaction_99'] = shopdata6.groupby(['id'])['transaction_99'].transform('cumsum')
  </code></pre>
  
  <p>The result does look okay, but is it correct ? </p>