How to check if all the elements in list are present in pandas column
You can build a set from the list of names for a faster lookup, and use set.issubset
to check if all elements in the set are contained in the column lists:
names = set(['a','c'])
df[df['char'].map(names.issubset)]
id char
1 2 [a, b, c]
2 3 [a, c]
5 6 [c, a, d]
Use pd.DataFrame.apply
:
df[df['char'].apply(lambda x: set(names).issubset(x))]
Output:
id char
1 2 [a, b, c]
2 3 [a, c]
5 6 [c, a, d]