Pandas · Keep matches or keep every search
Google Search Analytics
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
indexidlabel
01A
12B
events
indexidevent
0110
1111
indexidlabelevent
01A10
11A11
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
indexidlabel
01A
12B
events
indexidevent
0110
1111
indexidlabelevent_merge
01A10both
11A11both
22BNAleft_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
indexidlabel
01A
other
indexidlabel
01B
indexidlabel_leftlabel_right
01AB
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.

LANGUAGEPython · Pandas

Loading Python and Pandas…

Run the code to see DataFrame results here.