I have a pandas DataFrame that contains lists as entries
data = {'col1': [
['foo', 'bar', 'baz'],
['cat', 'dog', 'horse'],
[1, 2, 3]
]}
df = pd.DataFrame(data)
I then want to return rows using boolean mask IF 'foo' is in the list of any row (in this case, row 0). The following will return an empty DataFrame:
df[df['col1'] == 'foo']
The best way I can achieve the above is the following:
df[df['col1'].apply(lambda x: True if 'foo' in x else False)]
but I feel like there is a way to simplify this code. Any suggestions?