Using conditional statement to subtract scalar from pandas df column gives ValueError: The truth value of a Series is ambiguous
问题 I'm trying to execute: if df_trades.loc[:, 'CASH'] != 0: df_trades.loc[:, 'CASH'] -= commission and then I get the error. df_trades.loc[:, 'CASH'] is a column of floats. I want to subtract the scalar commission from each entry in that column. For example, df_trades.loc[:, 'CASH'] prints out 2011-01-10 -2557.0000 2011-01-11 0.0000 2011-01-12 0.0000 2011-01-13 -2581.0000 If commission is 1 , I want the result: 2011-01-10 -2558.0000 2011-01-11 0.0000 2011-01-12 0.0000 2011-01-13 -2582.0000 回答1: