title: conditional sums for pandas aggregate
body: <p>I just recently made the switch from R to python and have been having some trouble getting used to data frames again as opposed to using R's data.table. The problem I've been having is that I'd like to take a list of strings, check for a value, then sum the count of that string- broken down by user. So I would like to take this data:</p>
  
  <pre><code>   A_id       B    C
  1:   a1    "up"  100
  2:   a2  "down"  102
  3:   a3    "up"  100
  3:   a3    "up"  250
  4:   a4  "left"  100
  5:   a5 "right"  102
  </code></pre>
  
  <p>And return:</p>
  
  <pre><code>   A_id_grouped   sum_up   sum_down  ...  over_200_up
  1:           a1        1          0  ...            0
  2:           a2        0          1                 0
  3:           a3        2          0  ...            1
  4:           a4        0          0                 0
  5:           a5        0          0  ...            0
  </code></pre>
  
  <p>Before I did it with the R code (using data.table)</p>
  
  <pre><code>&gt;DT[ ,list(A_id_grouped, sum_up = sum(B == "up"),
  +  sum_down = sum(B == "down"), 
  +  ...,
  +  over_200_up = sum(up == "up" &amp; &lt; 200), by=list(A)];
  </code></pre>
  
  <p>However all of my recent attempts with Python have failed me:</p>
  
  <pre><code>DT.agg({"D": [np.sum(DT[DT["B"]=="up"]),np.sum(DT[DT["B"]=="up"])], ...
      "C": np.sum(DT[(DT["B"]=="up") &amp; (DT["C"]&gt;200)])
      })
  </code></pre>
  
  <p>Thank you in advance! it seems like a simple question however I couldn't find it anywhere.</p>