I have got this pandas DataFrame:
recipe_name ingredient_group weight%
pudding milk 0.60
pudding 2 sugar 0.10
pudding 2 sugar 0.70
pudding 2 milk 0.30
pudding 3 egg 0.20
I would like a pandas DataFrame like this:
recipe_name ingredient_group weight% new_column
pudding milk 0.60 0.60
pudding 2 sugar 0.10 0.80 (0.1+0.7)
pudding 2 sugar 0.70 0.80 (0.1+0.7)
pudding 2 milk 0.30 0.30
pudding 3 egg 0.20 0.20
The problem is that there are recipes that use the same ingredient multiple times (for example pudding 2 uses 2 times sugar).
I would like to create an extra column with the weight% and then with the sum of an ingredient that was used twice (see example above).
I tried to make a for loop for this problem, but I didn't succeed. Anyone an idea?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.