I have data as shown below:
I have a reference table shown below:
I want to loop through data table's "Description" to see if the string contains each word in reference table "Key" column, if so, I will enter corresponding category in reference table's column "Category" to data table's "Category" column. Both tables are Dataframe.
I am able to assign value to the data based on one key:
k = 'apple'
ind=df[df['Description'].str.contains(k)].index
df.loc[ind,'Category'] = 'A'
If I want to loop through the reference table "Key" column, should I convert the reference table to dictionary or just set key column as index? How should I loop it?