I need to set the value of one column based on the value of another in a Pandas dataframe. This is the logic:
if df[\'c1\'] == \'Value\': df[\'c2\'] = 10
I suggest doing it in two steps:
# set fixed value to 'c2' where the condition is met df.loc[df['c1'] == 'Value', 'c2'] = 10 # copy value from 'c3' to 'c2' where the condition is NOT met df.loc[df['c1'] != 'Value', 'c2'] = df[df['c1'] != 'Value', 'c3']