Course overviewGoogle Search · Connect searches, results, and clicks
Measure click-through rate correctly
Count clicked searches once and retain unclicked searches in the CTR denominator.
Step 1 of 3 · Learn
Count searches, not click events
Search CTR is searches with at least one click divided by all searches. Several clicks on one search still count as one clicked search. Deduplicate click search IDs before merging, or aggregate clicks to one row per search.
index
search
event
0
10
1
1
10
2
2
20
3
↓
index
search
clicked
0
10
1
2
20
1
Three click events belong to two clicked searches.
Restore searches with no click
Left-merge the unique clicked-search markers into all searches. Fill missing markers with 0 and keep matched markers as 1. .fillna(0).astype("Int64") produces integer flags; do not fill unrelated missing fields.
df
index
search
device
0
10
A
1
20
A
2
30
B
markers
index
search
clicked
0
10
1
↓
index
search
device
clicked
0
10
A
1
1
20
A
0
2
30
B
0
Every search contributes to the denominator, including devices with no clicks.
Compute rates from the same groups
Within each device, count all search rows and sum clicked flags, then divide clicked_searches by searches. Keep the rate as a proportion from 0 to 1. A device with searches but no clicks has rate 0. Do not average device rates to obtain overall CTR; use the total numerator divided by the total denominator.
▷ Your turn
Return search_id, device, and click_count for every search. Count click events by search_id, left-merge those counts into searches, and use integer 0 for searches without clicks. Preserve one row per search, sort search_id ascending, and save the DataFrame as result.