

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
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 "conversion rate" is the percentage of users who complete a desired action, like signing up. If 100 people visit your homepage and 10 sign up, the conversion rate is 10%. If only 5 of those signups submit a lesson, the "step conversion rate" from signup to lesson submission is 50%, but the "overall conversion rate" from homepage visit to lesson submission is only 5%.
Using these funnel_steps and funnel_counts:
funnel_steps = ["page_view", "signup", "lesson_submit", "purchase"]
funnel_counts = {}
eligible_users = None
for step in funnel_steps:
users_at_step = set(events[events["event_type"] == step]["user_id"])
eligible_users = (
users_at_step if eligible_users is None else eligible_users & users_at_step
)
funnel_counts[step] = len(eligible_users)
We can make a DataFrame and add columns for overall and step-by-step conversion rates:
funnel_df = pd.DataFrame(
{"step": funnel_steps, "users": [funnel_counts[s] for s in funnel_steps]}
)
funnel_df["conversion_rate"] = funnel_df["users"] / funnel_df["users"].iloc[0]
funnel_df["step_conversion"] = funnel_df["users"] / funnel_df["users"].shift(1)
Which prints something like:
step users conversion_rate step_conversion
0 page_view 8 1.000 NaN
1 signup 5 0.625 0.625000
2 lesson_submit 3 0.375 0.600000
3 purchase 2 0.250 0.666667
.iloc[0] selects the number of users at the first step (index 0).shift(1) method selects the previous row, so users.shift(1) gives the number of users at the previous step.SnackStack's growth team wants a simple, unordered check of how many users appear in one funnel step compared to another.
Complete the calculate_conversion_rate function. It accepts an events DataFrame (user_id and step columns) plus a from_step and a to_step, and returns the conversion rate between them as a float.