I have a table with shipments:
booking_order | driver_name | tonnage | stop_name | parcels | kgs |
---|---|---|---|---|---|
2794 | John | 3 | Warsaw | 200 | 180 |
2794 | John | 3 | Radom | 300 | 270 |
2794 | John | 3 | Krakow | 150 | 135 |
3005 | Mark | 5 | Gdansk | 500 | 450 |
3005 | Frank | 5 | Gdynia | 400 | 360 |
3005 | Frank | 5 | Sopot | 123 | 10.7 |
Task is to group all rows by booking order and to show for driver name, tonnage and stop_name as unique values inside (set with different delimiters) and sum for parcels and kgs.
Needed result is below:
booking_order | driver_name | tonnage | stop_name | parcels | kgs |
---|---|---|---|---|---|
2794 | John | 3 | Warsaw>Radom>Krakow | 650 | 585 |
3005 | Mark, Frank | 5 | Gdansk>Gdynia>Sopot | 1023 | 920.7 |
I only could do grouping, but don't know how to apply different methods to different columns correctly
import pandas as pd
excel=pd.read_excel('source.xlsx')
result=excel.groupby('booking_order').agg(lambda x: list(x)).reset_index()
result.to_excel('result1.xlsx')