FunctionRacerProblemsRace

Visits per User

MediumpandasPython

events has columns user and time (whole minutes), in any order. A user's first event starts a visit, and so does any event more than 30 minutes after that user's previous event. Return a dict from each user to their number of visits.

Example 1

events {"user":["ann","bob","ann","ann","bob","ann"],"time":[0,5,20,51,35,200]}
returns {"ann":3,"bob":1}

ann: 0 and 20 are one visit, 51 is 31 minutes after 20 so it starts a second, and 200 starts a third. bob: 5 and 35 are 30 apart, which is still one visit.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems