I want to keep only those words which are present in my list. All other words should get deleted.(pandas dataframe)
cuisine_list = ['breakfast', 'american', 'tea', 'chicken']
| name | cuisine |
|---|---|
| dominos pizza | breakfast american tea dine in |
| kfc | american chicken play area |
The result should look like this-
| name | cuisine |
|---|---|
| dominos pizza | breakfast american tea |
| kfc | american chicken |
I am using following code but its taking lot of time.
file1_cuisine = file1[["Cuisine"]]
for index, row in file1_cuisine.iterrows():
words_to_keep = []
for word in row[0].split(' '):
if word in words_to_match :
words_to_keep.append(word + ' ')
file1_cuisine.loc[index, 'final_input_text']= ''.join(words_to_keep)