I have a pandas dataframe where one column contains list objects which gives me dtype: object. The list objects are of different lengths.
features other_features
0 ["foo", "bar"] 2
1 ["foo", "dog"] 1
2 ["dog"] 4
I want to select the rows in my dataframe where the list has elements that are in a different list external_list = ["dog", "cat"].
In this case I would like the result to be the rows that contains dog or cat together with the other coulmns, which would be:
features other_features
1 ["foo", "dog"] 1
2 ["dog"] 4
I have tried isin, but from what I understand it requires the column type of the element to look at to not be a list of more than one object.
filter = df["features"].isin(["dog", "cat"])
It results in every element being False, which it should not since some should be True, and it is not returning the rest of the columns.
How can I solve this?