I'm trying to edit a schedule file in pandas, python 3 and am very stuck at the moment.
Basically, I have a schedule file like this:
id trip_id origin destination courier_status package_origin package_destination
1 1 A B False nan nan
1 2 B C True X Y
2 1 F G False nan nan
2 2 G H True Q R
2 3 H I False nan nan
If the courier_status is true, I want them (the person in id) to make a detour to the package_origin and package_destination before continuing to destination, thus changing their schedule file. Ideally, the new schedule file is supposed to be like this, newSchedule:
id trip_id origin destination status
1 1 A B normal
1 2 B X courier
1 3 X Y courier
1 4 Y C normal
2 1 F G normal
2 2 G Q courier
2 3 Q R courier
2 4 R H normal
2 5 H I normal
My idea was to make a new df, consisting of only additional trips, then append them to the existing schedule, then remove the duplicates and keep='last', afterwards apply the sort_values on id. However, I haven't been able to make the newSchedule DataFrame. Can anybody give me a hand or give me a direction on what kind of algorithm should I use? I was thinking of using a loop or using np.where?
The real data have many more columns and row, I just want to know how can I work with this. I am a rookie on working with python so I'm very lost at the moment.
Please help!