I would like to check if items in a List are in a Column from my DF.
The basics where straightforward:
fruit = ['apple','banana'] # This items should be in the column
fruit = ', '.join(fruit) # Think this is the point where it goes wrong...
fruit_resulst = df['all_fruit'].str.contains(fruit) # Check if column contains fruit
df_new = df[fruit_resulst] # Filter so that we only keep the TRUEs
This works, but not completely. It only works in this specific order, but I would like to have it working in all orders (e.g., if a column row contains ALL items from the list, then I would like to keep them. Else, remove.
df['all_fruit']
Apple, Banana #Return! Because it contains apple and banana
Banana # Do not return
Banana, Apple #Return! Because it contains apple and banana
Apple # Do not return
Apple, Banana, Peer #Return! Because it contains apple and banana
Thanks a lot in advance!