我有以下数据帧:
Course Orders Ingredient 1 Ingredient 2 Ingredient 3
starter 3 Fish Bread Mayonnaise
starter 1 Olives Bread
starter 5 Hummus Pita
main 1 Pizza
main 6 Beef Potato Peas
main 9 Fish Peas
main 11 Bread Mayonnaise Beef
main 4 Pasta Bolognese Peas
desert 10 Cheese Olives Crackers
desert 7 Cookies Cream
desert 8 Cheesecake Cream
我想计算每道菜每种配料的订购数量。成分在哪一列并不重要。你知道吗
以下数据帧是我想要的输出:
Course Ord Ing1 IngOrd1 Ing2 IngOrd2 Ing3 IngOrd3
starter 3 Fish 3 Bread 4 Mayo 3
starter 1 Olives 1 Bread 4
starter 5 Hummus 5 Pita 5
main 1 Pizza 1
main 6 Beef 17 Potato 6 Peas 21
main 9 Fish 9 Peas 21
main 11 Bread 11 Mayo 11 Beef 17
main 4 Pasta 4 Bolognese 4 Peas 21
desert 10 Cheese 10 Olives 10 Crackers 10
desert 7 Cookies 7 Cream 15
desert 8 Cheesecake 8 Cream 15
我尝试过使用groupby().sum(),但这对3列中的成分不起作用。你知道吗
我也不能使用lookup,因为在完整的数据帧中有一些实例,我不知道我在寻找什么成分。你知道吗
我不相信groupby或者其他类似的方法真的有什么好办法,尽管我很高兴被证明是错的。在任何情况下,以下不是特别漂亮,但它会给你什么你的追求。你知道吗
如果这是一个问题,你需要处理N和0计数。但这是一个微不足道的任务。你知道吗
相关问题 更多 >
编程相关推荐