当侧栏有卖出时,如何反转数量栏中的符号?不应更改所有其他值。下面的根本就不行,没有效果。
df[df['side'] == 'Sell']['quantity'] = df[df['side'] == 'Sell']['quantity'] * -1
最佳答案
引用Pandas indexing documentation ,并且在设置值时切勿根据您的示例使用链索引。
df.loc[df.side == 'Sell', 'quantity'] *= -1
关于 python Pandas : change one column conditional on another,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39415286/