Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 447

How to keep the most recent values and delete all other others in a column (pandas)

$
0
0

I'm trying to get the latest occurrence of an ID Name and I want to delete every other occurrence that happened before that time.

    ID Name     Comment        Time0     W12D0       Fine     12:17:371     W12D0     Random     12:20:102     W12D0       What     12:21:063     W12D4       Fine     08:20:144     W12D5     Random     10:11:125     W12D5       Fine     11:37:02..      ...        ...         ....

For example (according to the data above), the 'ID Name', 'W12D0', is associated with 3 occurrences:12:17:37 , 12:20:10 , 12:21:06

I want to only keep the row associated to that ID Name's latest time (in this case, it's 12:21:06). Every other row with W12D0 will be deleted. Essentially, I want something like this:

    ID Name     Comment        Time0     W12D0       What     12:21:061     W12D4       Fine     08:20:142     W12D5       Fine     11:37:02..      ...        ...         ....

How would I go about doing this?


Viewing all articles
Browse latest Browse all 447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>