I am stuck on trying to figure out how to add a row sum to a pandas pivot table. Would somebody please help point me towards the right direction.
This is my code below.
x.pivot_table(index = ["am","spot_or_contract"],
columns = "status",
values = "shipment_id",
aggfunc = "count").fillna('')
Thank you very much in advance
Look at margins
parameter in pivot_table:
x.pivot_table(index = ["am","spot_or_contract"],
columns = "status" ,
values = "shipment_id",
aggfunc = "count",
margins = True,
fill_value = "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With