title: Pandas: conditional group-specific computations
body: <p>Let's say I have a table with a key (e.g. customer ID) and two numeric columns C1 and C2. I would like to group rows by the key (customer) and run some aggregators like sum and mean on its columns. After computing group aggregators I would like to assign the results back to each customer row in a DataFrame (as some customer-wide features added to each row).</p>
  
  <p>I can see that I can do something like<br/>
  <code>df['F1'] = df.groupby(['Key'])['C1'].transform(np.sum)</code><br/>
  if I want to aggregate just one column and be able to add the result back to the DataFrame.</p>
  
  <p>Can I make it conditional - can I add up C1 column in a group only for rows whose C2 column is equal to some number X and still be able to add results back to the DataFrame?</p>
  
  <p>How can I run aggregator on a combination of rows like:<br/>
  np.sum(C1 + C2)?</p>
  
  <p>What would be the simplest and most elegant way to implement it? What is the most efficient way to do it? Can those aggregations be done in a one path?</p>
  
  <p>Thank you in advance.</p>