We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Time Patterns

It's common to want to know when users are most active:

events["hour"] = events["timestamp"].dt.hour
hourly_activity = events.groupby("hour")["user_id"].nunique()
peak_hour = hourly_activity.idxmax()

The idxmax() method returns the index label for the largest value. I often use it to find when it's best to send notifications or when to schedule downtime maintenance (jk we never have downtime).

Day-of-Week Patterns

events["day_of_week"] = events["timestamp"].dt.dayofweek
dow_activity = events.groupby("day_of_week")["user_id"].nunique()

B2B products spike Monday-Friday. Consumer products often spike on weekends. If your pattern doesn't match expectations, investigate further!

Assignment

SnackStack's marketing team wants to push recipe notifications at the hour when the most people are using their devices.

Complete the peak_activity_hour function. It accepts an events DataFrame with timestamp and user_id columns and returns the hour of day (023) with the most active users.