I am working on object detection project where my task is calculate for exactly how many seconds particular class was in the frame. I have a csv file of detected classes with their timestamp that looks like this:
I can input this csv into a pandas dataframe to calculate their timestamp range as finaltimestamp-intialtimestamp. But the catch is here is: suppose one class, let say HP, made an appearance for 5 seconds. After that, a new class kellogs is introduced and then HP reenters the frame.
Following the above final-intial logic fails here as there is a time gap after the same class appears again.
How to deal with this in pandas? I'm aware of .groupby() and .valueCounts() but they can't solve this problem directly.
Example data:
cat time
0 HP 06:35:03
1 HP 06:35:04
2 kellogs 06:35:42
3 kellogs 06:35:43
4 HP 06:35:45
Expected output
cat time
0 HP 00:00:03
1 kellogs 00:00:02
The output above should return as much time that each class was present in the frame. So in the above example, HP has 3 seconds and kellogs 2 seconds.
