Course overviewGoogle Search · Connect searches, results, and clicks
Keep matches or keep every search
Compare inner and left merges and identify searches without clicks.
Step 1 of 3 · Learn
Keep only matches
An inner merge keeps matching keys. When one search has several clicks, its search fields repeat once per click. validate="one_to_many" checks that the left search key is unique while allowing multiple right-side clicks.
df
index
id
label
0
1
A
1
2
B
events
index
id
event
0
1
10
1
1
11
↓
index
id
label
event
0
1
A
10
1
1
A
11
Two matching events produce two rows. The unmatched left row is absent.
Retain unmatched searches
A left merge keeps unmatched left rows, with missing right-side values. indicator=True adds _merge: both means matched, and left_only means unmatched. Select left_only rows to find searches without clicks.
df
index
id
label
0
1
A
1
2
B
events
index
id
event
0
1
10
1
1
11
↓
index
id
label
event
_merge
0
1
A
10
both
1
1
A
11
both
2
2
B
NA
left_only
The unclicked row remains, while matching rows still repeat for each event.
Name overlapping fields
When both inputs have a non-key column with the same name, suffixes=("_search", "_click") distinguishes the two sources. Select only needed columns when overlaps are unnecessary. Match indicators are categorical values; compare them to their text labels.
df
index
id
label
0
1
A
other
index
id
label
0
1
B
↓
index
id
label_left
label_right
0
1
A
B
The shared key appears once; both non-key labels keep their values.
▷ Your turn
Return search_id, query, and click_id for matching searches and clicks. Keep one row per click, so a search with multiple clicks appears multiple times. Exclude searches without clicks. Sort by search_id then click_id ascending and save the DataFrame as result.