I want to find the total time in each location, daily. I have dataframe with two columns. One for the locations and one for the arrival time to that location. The next location could be the shame as before because of a sensor reactivation. So i have something like this for example:
dateEntered location
2022-11-30 13:53:24 Bedroom01
2022-12-01 08:51:24 Bathroom01
2022-12-04 16:24:03 Bathroom01
2022-12-04 16:46:42 Bathroom01
2022-12-04 17:04:26 Bedroom01
2022-12-04 17:28:42 Bathroom01
2022-12-04 17:46:43 Livingroom01
2022-12-04 17:56:27 Bedroom01
2022-12-04 18:38:43 Livingroom01
I want code to have something like this as an output:
Date location TimeSpent
2022-11-30: Bedroom01 10:06:36 *First location
2022-12-01: Bedroom01 08:51:24 *Was the last location from last day
Bathroom01 15:08:36
2022-12-02: Bathroom01 24:00:00
2022-12-03: Bathroom01 24:00:00
2022-12-04: Bathroom01 17:22:27 *17:04:26 + 00:18:01
Bedroom01 01:16:32 *00:24:16 + 00:42:16
Livingroom01 05:31:01 *Last day so count until midnight and stop there . 00:09:44 + 05:21:17
So im thinking to count until midnight if there is no other entry before that. And keep counting for the same location for the next day until there is a new entry with a different location.So if one date has no entry the last location will get 24h for that day. Assume that ideally there will not be empty dates like now. I dont know if this is a good practice, but i can easilly drop the dates that will have one location with 24h spent at. So thats why imthinking this way. Every day has a sum of time spent in every location equal to 24h exactly.
I tried different solutions but nothing work like i want to. Especially to fiil the blank dates.
user25486187 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.