Need to modify the following df
gears milesbefore milesafter model_car safety_car gears milesbefore milesafter model_truck safety_truck
1 10 20 honda NTSB 5 100 200 volvo NTSB
1 10 20 honda NTFD 5 100 200 volvo NTFD
1 10 20 honda NRTB 5 100 200 volvo NRTB
1 10 20 toyota NTFD 5 100 200 merc NTFD
1 10 20 toyota NTFD 5 100 200 merc NTFD
1 10 20 toyota NRTB 5 100 200 merc NRTB
1 10 20 jeep NTSB 5 100 200 jaguar NTSB
1 10 20 jeep NTFD 5 100 200 jaguar NTFD
1 10 20 jeep NRTB 5 100 200 jaguar NRTB
1 10 20 jeep NRTB 6 1000 2000 jaguar NTFB
to this
model_car model_truck NTSB_car NTFD_car NRTB_car NTSB_truck NTFD_truck NRTB_truck
honda volvo 1:10:20 1:10:20 1:10:20 5:100:200 5:100:200 5:100:200
toyota merc 1:10:20 1:10:20 1:10:20 5:100:200 5:100:200 5:100:200
jeep jaguar 1:10:20 1:10:20 1:10:20 5:100:200 5:100:200 5:100:200
This involves three conditions one group by model_car and safety_car two is to avoid rows which look like this
1 10 20 jeep NRTB 6 1000 2000 jaguar NTFB
where the safety monitoring organization does not match. ideally i would live to save them in a different df.
and third is string concatenation which i can do it myself.
I really could not get beyond df.groupby()