Sub topic 8
Averaging Position Correctly
This chapter assumes you can read a Search Console export, you know what impressions and clicks are, and you can run short Python or SQL snippets. It covers one problem: how to combine position values across days, queries and pages without distorting them.
Why a simple average misleads
Search Console reports an average position for each row. A row is a combination of date, query, page and any other dimension you requested. Each row's position is already an average over that row's impressions.
If you average those row values with equal weight, a row with 2 impressions counts as much as a row with 2,000. Suppose a query ranks at position 3 on Monday with 1,000 impressions and at position 40 on Tuesday with 10 impressions. The simple mean is 21.5. The weighted figure is much closer to what users saw.
| Day | Position | Impressions | Position × impressions |
|---|---|---|---|
| Monday | 3 | 1,000 | 3,000 |
| Tuesday | 40 | 10 | 400 |
| Total | 1,010 | 3,400 |
Weighted position is 3,400 / 1,010, which is about 3.4.
The rule: sum first, divide last
Position is a ratio-like metric. Its correct aggregate is the sum of position × impressions divided by the sum of impressions. CTR follows the same pattern: sum clicks, sum impressions, then divide. Never average the stored CTR values.
In your daily table, store the raw ingredients, clicks, impressions and position. Derive weighted values at query time. Averages cannot be re-aggregated later, but sums can.
Weekly aggregation in Python
This code adds a helper column, sums at the weekly grain, then divides.
import pandas as pd
df = pd.read_csv("gsc_daily.csv", parse_dates=["date"])
# Columns: date, query, page, clicks, impressions, ctr, position
df["pos_x_impr"] = df["position"] * df["impressions"]
weekly = (
df.set_index("date")
.groupby("query")
.resample("W")[["clicks", "impressions", "pos_x_impr"]]
.sum()
.reset_index()
)
weekly["avg_position"] = weekly["pos_x_impr"] / weekly["impressions"]
weekly["ctr"] = weekly["clicks"] / weekly["impressions"]Weeks with zero impressions produce a division by zero, which pandas returns as NaN or infinity. Filter those rows before charting.
The same logic in SQL
-- PostgreSQL syntax; table gsc_daily(date, query, page, clicks, impressions, position)
WITH weekly AS (
SELECT
DATE_TRUNC('week', date) AS week,
SUM(clicks) AS clicks,
SUM(impressions) AS impressions,
SUM(position * impressions) / NULLIF(SUM(impressions), 0) AS avg_position
FROM gsc_daily
GROUP BY 1
)
SELECT
week,
clicks,
clicks - LAG(clicks) OVER (ORDER BY week) AS clicks_change,
avg_position
FROM weekly
ORDER BY week;NULLIF turns a zero denominator into NULL, so the query returns NULL instead of failing.
Common errors
- Averaging the
ctrcolumn. This gives low-traffic rows too much influence. Recompute CTR from summed clicks and impressions. - Averaging position across different grains. Weighting by impressions only works if every row you combine is a true impression count for that position. Mixing totals from different dimension sets gives inconsistent sums.
- Reading a movement as a ranking change. Weighted position also shifts when impressions move between queries. A site can gain impressions on page-two queries and see its average worsen while every individual query holds steady. Check the query-level view before concluding that rankings dropped.
- Ignoring rows without impressions. A zero-weight row contributes nothing, which is correct. Do not fill gaps with a made-up position.
Exercise
A query has two daily rows. Day 1: position 5, 300 impressions, 30 clicks. Day 2: position 12, 100 impressions, 2 clicks. What are the weighted average position and the CTR for the two days combined?
Show answer
Weighted position = (5 × 300 + 12 × 100) / (300 + 100) = (1,500 + 1,200) / 400 = 6.75. CTR = (30 + 2) / 400 = 0.08, or 8%. The simple average of the two positions would be 8.5, and the simple average of the two daily CTRs (10% and 2%) would be 6%. Both are wrong because they ignore volume.
Exercise
Your site's weighted average position worsened from 8 to 11 in one week, but no single query's position changed by more than half a place. What is the most likely explanation, and what would you check?
Show answer
The mix of impressions shifted toward queries where you rank lower, for example new long-tail queries on page two or three. Compare the impressions per query between the two weeks and recalculate the average for a fixed set of queries that appear in both weeks.