I have 2 csv file and i wanted to match the words from both, news.csv and dictionary.csv. If a word in news.csv exist in dictionary.csv, output 1. But since i have a lots of terms in my dictionary.csv and per row contains more than one word, i was unable to correctly match the words.
For example in news.csv i have these words
STORY
According to the 2011 National Health and Nutritional Status Survey, 12.4 per cent of the country's citizens have diabetes.
And in my dictionary.csv i have these terms
Terms
Diabetes Mellitus
Diabetes Inspidus
I should be getting 1 because the word diabetes exist in both of the csv files, but i didn't
I tried to join all the terms in dictionary.csv by using these code
news=pd.read_csv("news.csv")
dictionary=pd.read_csv("dictionary.csv")
pattern='|'.join(dictionary['Terms'])
news["contain diseases1"] = np.where(
news['STORY'].str.contains(pattern, na=False),
1, 0
)
news.to_csv("news1.csv")
But, since the code is only joining the terms in the dictionary.csv row by row instead of every words in the row, i couldn't get the output i wanted. I appreciate any help, TQ