I'm trying to create a new column based on conditions from others columns. I have this dataframe:
number, flag_new, flag_math
1, TRUE, TRUE
2, FALSE, TRUE
3, TRUE, FALSE
If the flag_new is True and the flag_math is also TRUE I want to have 1 on the new column. If the flag_new is FALSE and the flag_math is TRUE I want to add 0 else -1.
The expected result is:
number, flag_new, flag_math, new_Column
1, TRUE, TRUE, 1
2, FALSE, TRUE, 0
3, TRUE, FALSE, -1
For that I have this code:
df['new_col'] = np.where(df['flag_new'] == 'TRUE' and df['flag_math'] == 'TRUE',1,
np.where(df['flag_new'] == 'FALSE' and df['flag_math'] == 'TRUE',0, -1))
But I am getting the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What I am doing wrong?