Skip to content
Advertisement

Search substrings in strings and return relevant string when matched

I have a dataframe with product titles, which contain keywords, that can identify the product type as such:

df_product_titles dataframe

JavaScript

I have another dataframe with two columns, where the 1st column has the keyword and the relevant product type:

df_product_types dataframe

JavaScript

I want to search each keyword from product_types dataframe in the product_titles dataframe and return the relevant product type. Some product titles have multiple keywords and thus, have multiple product types, in which case it would be useful to return all product types in a single string separated by a comma.

df_output

JavaScript

I would greatly appreciate any help. Thanks!

Advertisement

Answer

I could came with this solution

JavaScript

output

JavaScript
Advertisement