title: Pandas groupby multiple columns take average of another based on condition
body: <p>I'm stuck on this and similar posts are creating a bit of a black hole for me. I'm still learning..</p>
  
  <p>I would like to take the mean of a group that meets a condition. My data looks like this:</p>
  
  <pre><code>user          date           Flag    Value  
  0    ron  12/23/2016        'flag'    10     
  1    ron  12/21/2016        'n/a'     25     
  2    ron   12/23/2016       'flag'    10     
  3    ron  12/21/2016        'n/a'     3      
  4   andy   12/22/2016       'flag'    5      
  5   andy   12/22/2016       'flag'    1      
  </code></pre>
  
  <p>I'd like to groupby user + Flag and create a new column 'Avg' that takes only the Avg values of 'flag'. So the data would look like this:</p>
  
  <pre><code>user          date           Flag    Value  Avg
  0    ron  12/23/2016        'flag'    10     10
  1    ron  12/21/2016        'n/a'     25     10
  2    ron   12/23/2016       'flag'    10     10
  3    ron  12/21/2016        'n/a'     3      10
  4   andy   12/22/2016       'flag'    5      3
  5   andy   12/22/2016       'flag'    1      3
  </code></pre>
  
  <p>I have something like this, but have tried many different variations:</p>
  
  <pre><code>groups = sample.groupby(['user','Flag'])
  flag = sample.groupby(['user','Flag'])['Value'].transform('mean')
  sample.loc[:,'Avg'] = np.select([flag.eq('flag'), groups.transform('mean')])
  </code></pre>
  
  <p>Guidance is appreciated..</p>