My question might be easy but I can't find the solution quickly. I have a dataframe 'df' and I want to check if elements in my list 'list' exist in any row of df.
This is a df example:

And this is my_list example:

In this case, I want to get row 2 of df as all elements in my_list exist in that row.
Thanks
You can try pandas isin
df.loc[df.isin(my_list).astype(int).sum(axis=1) == len(my_list), :]
where my_list being your list of searches you want to perform.
NOTE: In case you want a partial match you can play around with the condition.
Here's another way using applymap:
df.loc[df.applymap(lambda x: x in names).sum(1).eq(len(names))]
Color Number Code Flag
2 Yellow 19 ee 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With