Assume that I have this DataFrame (Animals column is of type pandas.Series):
| ID | Animals |
|---|---|
| 1 | [cat, dog, chicken] |
| 2 | [penguin] |
And these lists (It can be NumPy Array or Pandas Series if it is better for performance):
mammals = ['cat', 'dog', 'cow', 'sheep']
birds = ['chicken', 'duck', 'penguin']
What I am trying to do is to add two columns to my DataFrame which are ContainsBirds and ContainsMammals based on the contents of the Animals column.
Here is the final expected output:
| ID | Animals | ContainsBirds | ContainsMammals |
|---|---|---|---|
| 1 | [cat, dog, chicken] | 1.0 | 1.0 |
| 2 | [penguin] | 1.0 | 0.0 |