Skip to content
Advertisement

get string from list if it’s contained in another string column

I’ve a simple column of strings, and a list of strings.

JavaScript

I need to create another column in which every row contains the string contained in the list if they are in the string_col, if it contains two or more strings from the list, then I’d like to have more rows. The result should be something like this:

JavaScript

How can I do that? thanks

Advertisement

Answer

You can use str.findall:

JavaScript

If you want you can reset_index after that:

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