title: Selective group by, np.where Pandas/Python query
body: <p>df_have</p>
  
  <pre><code>A  B C
  1  1  10
  1  1  10
  1  2  5
  1  3  6
  1  4  7
  </code></pre>
  
  <p>df_want</p>
  
  <pre><code>A  B C    D
  1  1  10  20
  1  1  10  20
  1  2  5   5
  1  3  6   6
  1  4  7   7
  </code></pre>
  
  <p>Trying to group by column A, B only if column B is 1 or 2. If B is 1 or 2 then output column D as the SUM of column C. Else keep set column D = column C.</p>
  
  <p>Sample code gives error:</p>
  
  <pre><code>df_want['D']=np.where((df_want['B'].isin([1,2]), 
               df_want['A','B'].map(df_want.groupby(['A','B'])['C'].sum()), 
               df_want['C'])
  </code></pre>
  
  <p>The issue is occuring here: df_want['A','B'].map.. if I only put df_want.A.map then the code runs but the output is wrong. I need it to only map the sum if col B is 1 or 2</p>