I’m having two columns, one with the actual time and the other with rounded value of time. I want to remove the duplicate row. I need only the row which has the closest value to the rounded time.
For example: In this table, I want to take the second row only as it is closest to the rounded time.
Rounded_time | Actual_time |
---|---|
04:00:00 | 03:59:02 |
04:00:00 | 04:00:00 |
How do I solve this with Pandas?
You can use df.drop_duplicates() to remove duplicates. This function will remove all duplicates except the first one. It considers the initial value as distinct and the remaining values to be duplicate.