I have the following dataframe:
S A
1 1
1 0
2 1
2 0
I wanted to create a new 'Result' column that is calculated based on the values of both column A and column S.
I wrote the following nested np.where code
df['Result'] = np.where((df.S == 1 & df.A == 1), 1,
(df.S == 1 & df.A == 0), 0,
(df.S == 2 & df.A == 1), 0,
(df.S == 2 & df.A == 0), 1))))
but when I execute it, I get the following error:
SyntaxError: invalid syntax
What is wrong with my code?