I have below DF:
DF is sorted by VEHICLE_ID_FW and secondly by TRANSACTION_DATE_FW (ascending=False).
Task:
I need correct values in ODOMETER_FW column. (There are mileages of vehicles). For single VEHICLE_ID_FW I need check:
If some values in ODOMETER_FW is greater than last mileage in the month. –> if True –> convert this value to 0
If ODOMETER_FW for single VEHICLE_ID_FW < last mileage from month (always top record from ODOMETER_FW for single VEHICLE_ID_FW) – 10000 –> if True –> convert this value to 0.
I really tried to do this myself and I have written a code in python and converted everything to multiple list / matrix. Next I have written many difrent functions to correct it. It works but it is a tones of code lines and I think it is spaghetti code. I really doubt that what I have done is best way to solve it, especially that it is a possibility to make it in PANDAS ?