

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
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
The most fundamental question in event analytics: how many times did the thing happen?
Counting sounds trivial, but it often comes down to how you slice and group the data. Given our "events" DataFrame and event_type column, we can count in several ways. By event type:
print(events["event_type"].value_counts())
Which gives you:
page_view 4521
login 1893
purchase 312
signup 287
Name: event_type, dtype: int64
The value_counts() method gives you the overall distribution. Are most events page views? That's normal. Are most events purchases? Something is probably wrong with your data... there's no way your boss's product is that popular...
You can use the groupby() method to count the total events by user:
print(events.groupby("user_id")["event_type"].count())
Which prints:
user_id
101 73
202 23
532 45
...
Name: event_type, dtype: int64
You can also add a filter to count specific event types per user:
print(events[events["event_type"] == "purchase"].groupby("user_id").size())
Which prints:
user_id
101 23
202 5
...
dtype: int64
SnackStack's product team wants a quick snapshot of event activity: how many of each event type, plus which one happens most.
Complete the get_event_summary function. It accepts an events DataFrame with an event_type column and returns a dictionary mapping each event type to its count, with an extra "most_common" key.