Here is an example Dataframe:
id lists
1 ['dog', 'apple']
2 ['apple', 'cat']
3 ['pig', 'love']
4 ['help', 'out']
Now, I'd like to use lambda functions to create another column when apple
is in a lists list.
id lists flag
1 ['dog', 'apple'] 1
2 ['apple', 'cat'] 1
3 ['pig', 'love'] 0
4 ['help', 'out'] 0
My first thought is to use the following code but I'm getting a syntax error:
df.apply(lambda x: [1 if "apple" in i for i in x])