I have a list of item numbers as follows.
item_numbers = [1,2,5]
I also have a csv file that contains the ingredients of the item_numbers.
,sugar, protein, salt, oil
0, 0.2, 0.3, 0, 0
1, 0, 0, 0.2, 0.8
2, 0.4, 0, 0, 0
Now, I want to get the ingredients for the items in my list where the value is greater than zero (if value == 0, I don't need that ingredient)
E.g., item 1 in 'item_numbers' list -> [{'salt': 0.2}, {'oil': 0.8}]
My current code is as follows.
df = pd.read_csv(ingredients, sep = ',')
df = df.iloc[:,1:]
df = df.loc[item_numbers].dropna(how='all').gt(0).apply(lambda x: x.index[x].tolist(), 1)
ingredients = df.values.tolist()
print(ingredients)
Please help me.