A new session starts with a user's first event, and again whenever more than 30 minutes pass since that user's previous event. Store the number of sessions per user in result (a Series indexed by user).
import pandas as pd
events = pd.DataFrame({
"user": ["u1", "u1", "u1", "u1", "u2", "u2", "u2", "u3", "u3", "u3", "u3"],
"ts": pd.to_datetime(["2025-06-01 10:00", "2025-06-01 10:12", "2025-06-01 11:05", "2025-06-01 11:20",
"2025-06-01 09:00", "2025-06-01 09:25", "2025-06-01 09:50",
"2025-06-01 14:00", "2025-06-01 14:10", "2025-06-01 15:00", "2025-06-01 16:00"]),
"event": ["open", "search", "open", "buy", "open", "search", "buy", "open", "search", "search", "open"],
})Store your final answer in a variable named result.
Each hint gives a little more help. Try on your own first.
Run your code to see the output here.