I have a Pandas DataFrame, df
, with the following columns:
user_id, date_of_visit
I want to find all user_id
s who visited at least twice in any 4 day window. So if I had:
user_id, date_of_visit
1, 1/4/15
1, 1/6/15
2, 1/4/15
2, 1/12/15
2, 1/23/15
Then my function would return [1]
I could just go through each row, but I'm wondering if there's a better way to leverage Pandas. Maybe something with:
df.groupby('user_id')...
?
Thanks!