首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何展示制造产品的产品?

如何展示制造产品的产品?
EN

Stack Overflow用户
提问于 2022-10-17 14:37:24
回答 1查看 33关注 0票数 -3

我有这样的数据:

代码语言:javascript
复制
df = pd.DataFrame({"Fruits": ["orange_farm1", "orange_farm2", "orange_farm3", "orange_farm4", "orange_farm5", "apple_farm1", "apple_farm2", "apple_farm3", "apple_farm4", "banana_farm1", "banana_farm2", "banana_farm3", "banana_farm4", "orange_farm5", "apple_farm4", "orange_farm4", "apple_farm1","banana_farm1"], "Quantity":[400, 580, 300, 260, 540, 590, 400, 350, 480, 500, 590, 400, 350, 260, 540, 590, 400, 350], "Juice": ["mixedjuice1","mixedjuice1", "mixedjuice2", "mixedjuice2", "mixedjuice3", "mixedjuice3", "mixedjuice1", "mixedjuice3", "mixedjuice2", "mixedjuice2", "mixedjuice1", "mixedjuice2", "mixedjuice3", "mixedjuice3", "mixedjuice1", "mixedjuice2", "mixedjuice2", "mixedjuice3"], "used_qty": [50,60,70,2,40,12,34,40,50,20,13,22,14,40,50,20,13,24]})

我需要知道怎样才能在数量和百分比上找到每种水果汁的总量。有人能帮我吗?

输出:

代码语言:javascript
复制
df2 = pd.DataFrame({"Fruits":["orange_farm1", "orange_farm2", "apple_farm2", "banana_farm2", "apple_farm4", "orange_farm3", "orange_farm4", "apple_farm4", "banana_farm1", "banana_farm3", "orange_farm4", "apple_farm1","orange_farm5", "apple_farm1", "apple_farm3", "banana_farm4", "orange_farm5",  "banana_farm1"], 
                "Juice": ["mixedjuice1", "mixedjuice1", "mixedjuice1", "mixedjuice1", "mixedjuice1", "mixedjuice2", "mixedjuice2", "mixedjuice2", "mixedjuice2", "mixedjuice2", "mixedjuice2", "mixedjuice2", "mixedjuice3",  "mixedjuice3",  "mixedjuice3", "mixedjuice3", "mixedjuice3", "mixedjuice3"], 
                "% used_qty": [24.15, 28.99, 16.43,6.28, 24.15,35.53,1.02,25.38,10.15,11.17,10.15,6.60,23.53,7.06,23.53,8.24,23.53,14.12], 
                "% Quantity": [12.50, 10.34,8.50,2.20,9.26,23.33,0.24,10.42,4.00,5.50,2.13,3.25,5.00,2.03,11.43,4.00,5.00,6.86]})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-17 16:07:50

您可以使用lambda函数在每一行上应用计算,如下所示,

不知道'% used_qty'列的计算,因此还没有完成,但仍然可以在这里插入计算df.apply(lambda row: <<YourCalculation>>, axis=1)

代码:

代码语言:javascript
复制
df['% Quantity'] = df.apply(lambda row: row.used_qty/row.Quantity*100,axis=1)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74098905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档