I am working on my Date-A-Scientist Capstone Project.
I’d like to create a column in the df aggregating values of another one.
Basically group the 17 different diets on df[diet] into 3 or 4 (contains vegetarian/vegan, contains kosher/halal, contains anything, other)
I’ve been trying to use a lambda function, very similar than the first class/second class task in the Titanic project, combining with some Internet research, but I keep getting an error.
Here’s my code:
df['Diet_agg'] = df.apply(lambda row: 'Vegetarian/Vegan' if row['diet'].str.contains('Vegetarian'|'Vegan'), 'Religious' if row['diet'].str.contains('kosher'|'halal'), else 'Anything/Other', axis=1
Could you please help me with that ?