Skip to content
Advertisement

How to choose values from col1 if their values are in col2 but not on list in Python Pandas?

I have DataFrame in Python Pandas like below:

JavaScript

And I need to select only these people from “col1” which have value from “col” in column “description” and something else (nevermind before or after), but it something else could not be from bad_list.

So I need to select only John Bravo and Ann Still because they have their value from “col1” in column “description” and does not have words from bad_list with their name in column “description”.

How to do that in Python Pandas?

Advertisement

Answer

Try:

JavaScript

Prints:

JavaScript

EDIT: To check if value from col1 is in description:

JavaScript

EDIT2: To ignore case:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement