I have a data set like this.
df = pd.DataFrame({"A" :[1,1,3,4], "B": [1,3,2,2]})
I want to create a new column which is C with type 1 if A = 1 & B =(1,3)
I used .loc
and my code is
df.loc[(df['A'] == 1)&(df['B'] == 1), 'C'] = 'type 1'
df.loc[(df['A'] == 1)&(df['B'] == 3), 'C'] = 'type 1'
The above is working, but when I use
df.loc[(df['A'] == 1)&(df['B'] == (1,3)), 'C'] = 'type 1'
Nothing happens, it doesn't show error and column is also not updated.
The expected output is
A B C
1 1 type 1
1 3 type 1
3 2 Nan
4 2 Nan
Is there any other way?
Thanks in advance