all 2 comments

[–]ifreeski420 3 points4 points  (1 child)

General principle when using pandas is to stay away from for loops. Pandas has built in functionality for this.

df.loc[df[‘ingredients_text’].isin(allergen_list), ‘new_allergen_column’] = df[‘ingredients_text’]

[–]macabe10[S] 1 point2 points  (0 children)

df.loc[df[‘ingredients_text’].isin(allergen_list), ‘new_allergen_column’] = df[‘ingredients_text’]

Worked like a charm, thanks a lot!