I need to match keywords listed in pandas column with the keywords from a list and create a new column that consists of matched words. Example:
my_list = ['machine learning', 'artificial intelligence', 'lasso']
Data:
listing keyword_column
I am looking for machine learning expert machine learning
Machine learning expert that knows lasso machine learning, lasso
Need a web designer
Artificial Intelligence application on... artificial intelligence
3
Answers
Use
Series.str.findall
for get all values in list, join togehter bySeries.str.join
and if necessary convert to lowercase bySeries.str.lower
:Also here are used word boundaries with
b
for correct matching whole words frommy_list
.Or:
You can also use
str.lower
+str.findall
+str.join
to solve your problem:And now:
Is:
flashtext can also be used to extract keyword