Course overviewGoogle Search · Connect searches, results, and clicks
Add page details with merge
Attach page metadata to result impressions without multiplying or dropping rows.
Step 1 of 3 · Learn
Match an explicit key
Use .merge(details, on="page_id", how="left") to attach lookup columns. Every left row is retained; a repeated left key receives the same lookup detail on each row. Select only the lookup columns you need.
df
index
event
page_id
0
1
10
1
2
10
2
3
20
details
index
page_id
label
0
10
A
1
20
B
↓
index
event
page_id
label
0
1
10
A
1
2
10
A
2
3
20
B
Each event stays a row; repeated page IDs reuse the same detail.
Check the lookup is unique
validate="many_to_one" allows repeated keys on the left but requires unique keys on the right. It raises an error if the lookup would multiply rows. Do not silently discard conflicting lookup rows to hide that error.
Keep unmatched rows
A left merge fills unmatched details with missing values. Here, page_id is the lookup key, while (search_id, position) identifies a result impression. Preserve that grain: do not deduplicate result rows by page_id. Sort the result explicitly when an output order is required.
df
index
event
page_id
0
1
10
1
2
30
details
index
page_id
label
0
10
A
↓
index
event
page_id
label
0
1
10
A
1
2
30
NA
A missing lookup keeps the event and leaves its detail missing.
▷ Your turn
Attach each page's domain to every row of search_results using page_id. Return search_id, position, page_id, and domain. Keep all result rows, including any unmatched page IDs with missing domain; sort by search_id then position ascending. Save the DataFrame as result.