title: Pandas conditional computation based on multiple columns
body: <p>Considering this dataframe:</p>
  
  <pre><code>data = {'A':[1.5, 2, 3, 4], 'B':[3, 5, 8, 7], 'C':['abc', 'def', 'zyw', 'lol'], 'D':['AAA', 'AAA', 'BBB', 'CCC']}
  
  df = pd.DataFrame(data)
  </code></pre>
  
  <p>I'd like to compute the sum of the <code>A</code> column based on condition <code>x &lt;= 2.5 &amp; D == 'AAA'</code> and append the result to the same dataframe, but without the rows that match the condition. The strings should be concatenated.</p>
  
  <p>So, I came up with this:</p>
  
  <pre><code>logic = (df['A'] &lt;= 2.5) &amp; (df['D'] == 'AAA')
  df_1 = df[logic].sum()
  df_2 = df[~logic]
  df_2.append(df_1, ignore_index=True)
  </code></pre>
  
  <p>returning</p>
  
  <pre><code>    A   B   C       D
  0   3.0 8   zyw    BBB
  1   4.0 7   lol    CCC
  2   3.5 8   abcdef AAAAAA
  </code></pre>
  
  <p>Is there any other, more pythonic (oneliner maybe) solution?</p>