我希望能够按订单编号获取产品的数量。我已经得到了总产品数量(感谢另一个SO用户的帮助),但是我无法计算出不同产品的数量。
以下是我的代码:
如何生成“distinct_productcount”?
以下是我的代码:
data['total_productcount'] = data.groupby(['order_number'])['order_number'].transform('size')
并且它会给予:
order_number product_id total_productcount
171-1046037-0511522 4260179734731 5
171-1046037-0511522 4054673034394 5
171-1046037-0511522 4054673001235 5
171-1046037-0511522 4054673005752 5
171-1046037-0511522 5011385960075 5
171-1046037-0511522 5011385960075 5
这是我想要生成的数据框(包括:distinct_productcount)
order_number product_id total_productcount distict_productcount
171-1046037-0511522 4260179734731 5 1
171-1046037-0511522 4054673034394 5 1
171-1046037-0511522 4054673001235 5 1
171-1046037-0511522 4054673005752 5 1
171-1046037-0511522 5011385960075 5 1
171-1046037-0511522 5011385960075 5 2
如何生成“distinct_productcount”?
df = df.assign(distinct_productcount=s)
- piRSquared