Python Forum
Give visit number ( or counter) within the same time frame - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Give visit number ( or counter) within the same time frame (/thread-37575.html)



Give visit number ( or counter) within the same time frame - balthordu - Jun-27-2022

Hi all

Thanks in advance for your help.

I have this below dataset.

Output:
Visitor ID Visit time AAA 27/06/2022 10:00:00 AAA 27/06/2022 10:05:21 AAA 27/06/2022 10:32:01 AAA 27/06/2022 13:04:01 AAA 28/06/2022 13:05:01 BBB 27/06/2022 11:00:00 BBB 27/06/2022 11:24:00 BBB 29/06/2022 11:24:00
I need for each visitor ID, assign a same visit number if the visit times ares in a 30min windows.
The result below would be

Output:
Visitor ID Visit time Visit number AAA 27/06/2022 10:00:00 1 AAA 27/06/2022 10:05:21 1 (same id than before as this time visitis less than 30min than the visit before) AAA 27/06/2022 10:32:01 1 (same id than before as this time visitis less than 30min than the visit before) AAA 27/06/2022 13:04:01 2 (as the difference btw this time visit and preivous visit is more than 30min) AAA 28/06/2022 13:05:01 2 (same id than before as this time visitis less than 30min than the visit before) BBB 27/06/2022 11:00:00 1 BBB 27/06/2022 11:34:00 2 (as the difference btw this time visit and preivous visit is more than 30min) BBB 29/06/2022 11:36:00 2 (same id than before as this time visitis less than 30min than the visit before)
Could you please tell me how I can do this in Python ? Or what logic I could use ?
Again, thanks a lot
B.


RE: Give visit number ( or counter) within the same time frame - Larz60+ - Jun-27-2022

what have you tried so far?