2

I have geodataframe about vessel position which include unique code called 'mmsi' and time series. In the following 'mmsi' column has more than 1 'mmsi' code and time series (* mark).

           mmsi                 time
98    525107006  2018-12-07T23:55:48
295   563038200  2018-12-07T23:52:42
627   477162400  2018-12-07T23:49:50
704   244850097  2018-12-07T23:47:41
1141  352366000  2018-12-07T23:30:00*
1166  376265000  2018-12-07T23:28:29
1319  352366000  2018-12-07T23:19:53*
1345  477858800  2018-12-07T23:18:14

How to retain last position of a vessel of 1 'mmsi' considering the latest time and remove the rest?

I expect that it can be execute in a loop for other 'mmsi' code that have same issue.

1

Sort by time and drop duplicate mmsis keeping last:

newdf = df.sort_values('time').drop_duplicates('mmsi', keep='last')
  • 1
    Yes, it works. Thank you very much @BERA :-) – Suhendra Aug 8 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.