python的枢轴表(熊猫)
我是Python(使用Pandas)的新手。请帮助。
我的数据框中有两个列 - 权重转换(float)和sales_units(int)。 我只想按(sum)通过wigath_conversion进行sales_units。
示例数据
weight_conversion sales_units
0.1 1
0.1 2
50 100
50 200
96.1 20
314.4 2
500 100
500 200
我尝试了两种方法:
- by in pandas:complat by in pandas:
df.groupby(['stoge_conversion'])['sales_unit']。sum()
df.groupby([[ '
df.pivot_table(index ='stroge_conversion',values ='sales_unit', aggfunc ='sum')
必需的输出:我需要一个简单的枢轴表,其中我的行作为weight_conversion以及销售单元的总和。
我在python pandas中获得的输出如下(很奇怪): weight_conversion
0 3300000000000000000000000000034000000000000000...
0.1 0000100001000000000000001000000020050000000000...
0.2 0000000000000000000000000000001000000001100000...
0.3 000000000000000000000300000
0.4 0000000000100000000000000000000000000000000001...
...
90 000000000102009
92 0000200011000000000000010001000000000000000020...
92.1 0000001000000000000000003
96 2000000000000000000000000000000000001100000000...
96.1 0000000000000000000000000000000000000000000000...
名称:sales_unit,长度:96,dtype:对象
样本输出
weight_conversion sales_units
0.1 3
50 300
96.1 20
314.4 2
500 300
请帮助。**
I'm very new to python (using pandas). Kindly help.
There are two columns in my dataframe - weight conversion (float) and sales_units (int). I simply want to group by (sum) the sales_units by weight_conversion.
Sample Data
weight_conversion sales_units
0.1 1
0.1 2
50 100
50 200
96.1 20
314.4 2
500 100
500 200
I have tried two ways:
- GROUP BY IN PANDAS :
df.groupby(['weight_conversion'])['Sales_Unit'].sum()
PIVOT TABLE IN PANDAS:
df.pivot_table(index = 'weight_conversion', values='Sales_Unit',
aggfunc ='sum')
Required Output: I need a simple pivot table where I have rows as weight_conversion along with sum of sales units.
The output I'm getting in Python Pandas is as follows (so weird):
weight_conversion
0 3300000000000000000000000000034000000000000000...
0.1 0000100001000000000000001000000020050000000000...
0.2 0000000000000000000000000000001000000001100000...
0.3 000000000000000000000300000
0.4 0000000000100000000000000000000000000000000001...
...
90 000000000102009
92 0000200011000000000000010001000000000000000020...
92.1 0000001000000000000000003
96 2000000000000000000000000000000000001100000000...
96.1 0000000000000000000000000000000000000000000000...
Name: Sales_Unit, Length: 96, dtype: object
sample output
weight_conversion sales_units
0.1 3
50 300
96.1 20
314.4 2
500 300
Please help.**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不需要枢轴表才能获得所提供的样本输出。以下是您提到的所需输出的工作
I dont think you need PIVOT table for the sample output you have given. Below worked as for the required output you mentioned