I have a pandas dataframe as:
word_list
['nuclear','election','usa','baseball']
['football','united','thriller']
['marvels','hollywood','spiderman']
....................
....................
....................
I also have multiple number of lists with categories names,something as:-
movies=['spiderman','marvels','thriller']'
sports=['baseball','hockey','football']
,
politics=['election','china','usa']
and many others categories.
All I want to match the keywords of pandas column word_list
with my categories lists and assign the corresponding lists name in seperate column if keywords gets matched together and if any keywords not gets matched in any of the list then simply put as miscellaneous
So, output I'm looking for as:-
word_list matched_list_names
['nuclear','election','usa','baseball'] politics,sports,miscellaneous
['football','united','thriller'] sports,movies,miscellaneous
['marvels','spiderman','hockey'] movies,sports
.................... .....................
.................... .....................
.................... ....................
I successfully get the match keywords as:-
for i in df['word_list']:
for j in movies:
if i in j:
print (i)
but this gives me the list of matched keywords. How I get the list names and add it into pandas column?
See Question&Answers more detail:
os