1conditions = [
2 df['gender'].eq('male') & df['pet1'].eq(df['pet2']),
3 df['gender'].eq('female') & df['pet1'].isin(['cat', 'dog'])
4]
5
6choices = [5,5]
7
8df['points'] = np.select(conditions, choices, default=0)
9
10print(df)
11 gender pet1 pet2 points
120 male dog dog 5
131 male cat cat 5
142 male dog cat 0
153 female cat squirrel 5
164 female dog dog 5
175 female squirrel cat 0
186 squirrel dog cat 0
19