I have a dataframe has users, actions and the time users took the actions. I want to group actions into a list if they satisfy BOTH of the two conditions: 1. actions were taken by the same user 2. actions were taken within 20 minutes.
At the moment I'm trying to use timedelta to calculate time difference with iteration and read this post but that's not what I'm looking for. I struggle to find similar examples.
the dataframe has thousands of rows, this is part of it
user action time
A browse 2018-07-01 06:00:00
A edit 2018-07-01 06:10:00
B signin 2018-07-01 06:00:00
B browse 2018-07-01 06:11:00
B edit 2018-07-01 07:00:00
The expected output will be a list of the actions that satisfied the conditions
output
[[browse, edit], [signin, browse]]
The last 'edit' did by user B is not in it because (07:00:00) - (06:11:00) > 20 min
Any suggestions about how can I do this ? Thank you very much in advanced !