我一直试图弄清楚如何在pandas数据透视表中添加行和。请有人帮我指出正确的方向。
这是我的代码如下。
x.pivot_table(index = ["am","spot_or_contract"],
columns = "status",
values = "shipment_id",
aggfunc = "count").fillna('')
非常感谢您提前
答案 0 :(得分:2)
查看pivot_table中的margins
参数:
x.pivot_table(index = ["am","spot_or_contract"],
columns = "status" ,
values = "shipment_id",
aggfunc = "count", margins=True)\
.fillna('')