

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 9
click for more info
Not enough gems
Cost: 6 gems
1: Event Data
incomplete
2: Event Structure
incomplete
3: Event Counting
incomplete
4: Resample
incomplete
5: Resample Aggregations
incomplete
6: Active Users
incomplete
7: Time Patterns
incomplete
8: Funnel Metrics
incomplete
9: Conversion Rates
incomplete
10: Funnel Drop-Offs
incomplete
11: Ordered Funnels
incomplete
12: Cohorts
incomplete
13: Cohort Retention
incomplete
14: Rolling Metrics
incomplete
15: Growth Rates
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Daily, weekly, and monthly rollups are the bread and butter of product analytics, and resample() is built for exactly that.
It's kinda like groupby(), but for time periods. It needs datetime-like values, either in a DatetimeIndex or in a column passed with on=.
events = events.set_index("timestamp")
print(events.resample("D").size())
Which prints something like:
timestamp
2023-12-29 3
2023-12-30 3
2023-12-31 4
2024-01-01 4
2024-01-02 4
2024-01-03 5
Freq: D, dtype: int64
The set_index() method moves the timestamp column into the index so pandas can group rows by time. Some of the common frequency codes for resampling are:
| Code | Period |
|---|---|
"h" |
Hourly |
"D" |
Daily |
"W" |
Weekly (ends Sunday) |
"ME" |
Month end |
I always start an event analysis with a (usually daily) event count chart. If there are gaps, spikes, or drops, you want to know about them before you start calculating metrics.
SnackStack's dashboards need event counts per time bucket.
Complete the get_event_counts function. It accepts an events DataFrame with a timestamp column and a freq frequency code, and returns a DataFrame of event counts, one row per bucket.