Pandas · Compare result positions
Google Search Analytics
Course overviewGoogle Search · Build a search performance report

Compare result positions

Measure result CTR using impressions and distinct clicked result keys.

Step 1 of 3 · Learn

Count at result-impression level

Each search_results row is an impression identified by (search_id, position). Result CTR at a position is clicked impressions divided by all impressions at that position. This differs from search CTR: one search can contribute several result impressions.

Collapse repeated clicks on a result

Deduplicate clicks using both search_id and position, then attach a marker to search_results with a one-to-one left merge. Repeated clicks on the same result count once; clicks on different positions within a search remain separate.

indexsearchpositionevent
01011
11012
21023
32014
indexsearchpositionclicked
01011
21021
32011
Four events identify three clicked impressions, not two clicked searches.

Keep positions with no clicks

Fill absent markers with 0 and group the full impression table by position. Count rows for impressions and sum markers for clicked_results. Divide within each position and retain positions with zero clicked results.

indexpositionclicked
011
110
220
indexpositionimpressionsclicked_resultsresult_ctr
01210.5
12100
The unclicked second position stays in the report with a rate of zero.
▷ Your turn

From search_results, return position and impressions, counting every result row once within its position. Sort position ascending and save the DataFrame as result.

LANGUAGEPython · Pandas

Loading Python and Pandas…

Run the code to see DataFrame results here.