Created dictionary called items. Combined values for different keys and put into variable food_list.
items={'Food':['Ice Cream','Salad'],'Computer':['Laptop','Notebook']
food_list= '|'.join(items['Food'])
Description Amount
Lenovo Laptop 300
Chicken Salad 40
Dell Notebook 250
Chocolate Ice Cream 3
I tried to find a string based on dictionary values. If the string is in the dictionary, then the row in the dataframe contains the string. I take the amount it is associated with and add up the total row amounts that fit the condition.
total_amount=df.loc[df['Description'].str.contains(food_list,na=False)
==df['Amount'].sum()]
I usually run the code and get
Empty DataFrame
Columns: [Date, Description, Amount]
Index: []