擅长:python、mysql、java
<p>首先将<code>sell</code>值强制转换为负数,然后使用<code>groupby.sum</code>:</p>
<pre><code>df['amount'] = np.where(df['order_type'].eq('Sell'), -df['amount'], df['amount'])
df.groupby('client', as_index=False)['amount'].sum()
</code></pre>
<hr/>
<pre><code> client amount
0 Aaron 100
1 Jeff 200
2 John 0
</code></pre>