Python pandas: change one column conditional on another
<p>How can I reverse the sign in the quantity column whenever the side column has a sell? All other values should not be changed. The following is simply not working, it has no effect.</p>

<pre><code>df[df['side'] == 'Sell']['quantity'] = df[df['side'] == 'Sell']['quantity'] * -1
</code></pre>

<p>Refer to the <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#different-choices-for-indexing" rel="nofollow">Pandas indexing documentation</a>, and never use chain indexing per your example when setting values.</p>

<pre><code>df.loc[df.side == 'Sell', 'quantity'] *= -1
</code></pre>

python pandas