Sub topic 8
Averaging position correctly
This chapter assumes you can read a Search Console performance table and write basic pandas or SQL. It also assumes you have the daily table from the previous chapter, with one row per date, query and page. Here you will learn why a plain average of position values gives wrong answers, and how to compute the right one at any level of grouping.
What a position value is
Each row in Search Console data reports position. That number is already an average. For a given date, query and page, Google averages the position of your topmost result across every impression in that row. A row with 1,000 impressions and a position of 3.0 summarizes 1,000 separate search results pages. Position 1 is the top of the page.
Because each row is an average over a different number of impressions, rows do not carry equal information. A row built from 1,000 impressions says far more about your visibility than a row built from 2. Treating them equally is the core mistake in position reporting.
Why the simple mean is wrong
Suppose a page has two daily rows for one query:
| Date | Position | Impressions |
|---|---|---|
| Monday | 3.0 | 1000 |
| Tuesday | 9.0 | 100 |
The simple mean is (3.0 + 9.0) / 2 = 6.0. That implies a typical searcher saw you around position 6. Most searchers actually saw you at position 3, because 1,000 of the 1,100 impressions happened on Monday.
The impression-weighted average multiplies each position by its impressions, sums those products, and divides by total impressions:
(3.0 × 1000 + 9.0 × 100) / 1100 = 3900 / 1100 ≈ 3.55
This is the value Search Console would show if you requested the two days as one row. Weighted aggregation reproduces the number the tool itself would compute, which is why it is the right default.
import pandas as pd
df = pd.DataFrame(
{
"date": pd.to_datetime(["2026-03-02", "2026-03-03"]),
"position": [3.0, 9.0],
"impressions": [1000, 100],
}
)
simple = df["position"].mean()
weighted = (df["position"] * df["impressions"]).sum() / df["impressions"].sum()
print(f"simple mean: {simple:.2f}")
print(f"weighted mean: {weighted:.2f}")The output is simple mean: 6.00 and weighted mean: 3.55.
The same rule for CTR
Click-through rate (CTR) is clicks divided by impressions. Like position, it is a ratio, and ratios cannot be averaged directly. A row with 1 click from 5 impressions has a CTR of 20%, and a row with 50 clicks from 5,000 impressions has a CTR of 1%. The mean of those is 10.5%, but the real CTR is 51 / 5005, about 1.02%.
The rule for any ratio metric is to store the numerator and the denominator, sum each separately, and divide last. For CTR the parts are clicks and impressions. For position, the numerator is the sum of position × impressions, and the denominator is impressions.
A reusable rollup function
Wrap the logic once so every report uses it:
import pandas as pd
def rollup(df: pd.DataFrame, by: list[str]) -> pd.DataFrame:
"""Aggregate daily GSC rows with correct ratio metrics."""
d = df.assign(pos_x_impr=df["position"] * df["impressions"])
out = d.groupby(by, as_index=False)[["clicks", "impressions", "pos_x_impr"]].sum()
denom = out["impressions"].where(out["impressions"] > 0)
out["ctr"] = out["clicks"] / denom
out["avg_position"] = out["pos_x_impr"] / denom
return out.drop(columns="pos_x_impr")The where call turns a zero denominator into NaN, so a group with no impressions reports a missing value instead of a divide-by-zero error or a misleading zero.
Weekly rollups in pandas and SQL
Daily position is noisy, so many reports use weekly values. Resample the daily table with the same weighted approach:
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 no impressions for a query produce NaN from the division, which is the correct signal that there was nothing to measure.
The SQL version works at site level and adds a week-over-week change in clicks:
-- 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(SUM(impressions), 0) plays the same role as where in pandas. Note that position is also a column name in some SQL dialects' function names, so quote it if your database complains.
Gotchas
Mix shift can make a healthy site look worse
An average over many queries changes when the set of queries changes, even if no single query moves. Consider two queries across two weeks:
| Query | Week 1 position | Week 1 impressions | Week 2 position | Week 2 impressions |
|---|---|---|---|---|
| A (head term) | 2.0 | 1000 | 1.8 | 1000 |
| B (long tail) | 30.0 | 100 | 25.0 | 1900 |
Both queries improved. The weighted position for the week still went from (2000 + 3000) / 1100 ≈ 4.5 to (1800 + 47500) / 2900 ≈ 17.0. The site gained a lot of long-tail visibility at modest positions, which drags the average down. This is progress, not a drop.
Two habits protect you from misreading it:
- Report position inside a fixed segment, such as top queries by clicks last year, so the population does not change underneath you.
- Report the distribution of impressions across position buckets (1–3, 4–10, 11–20, 21+) next to the average. In the example, impressions in the top 3 stay flat while the 21+ bucket grows, and that tells the real story.
Rows only exist where impressions exist
A query that fell off the first page entirely may still have a few impressions at position 60, or none. A query with zero impressions produces no row at all. Position series therefore have gaps, and a gap is not a position of 0. Do not fill missing positions with 0 or with the previous value. Leave them missing.
Position depends on the dimensions you request
Search Console computes position at the level of the rows you ask for. A query-and-page row gives the position of that page for that query. A page-only row averages across all queries that page appeared for, which mixes head and long-tail terms. Weighted rollups from fine-grained rows should match coarse requests closely, but not exactly. Privacy filtering drops some anonymized queries from query-level rows, so totals from query rows can fall short of the property total. Pick one level of the data model for each report and stay with it.
Median and clicks-based weights are alternatives, not corrections
You may weight by clicks to describe the position where your traffic came from, or look at the median to resist outliers. Both answer different questions. Impression weighting answers "where did searchers see us," and it matches the tool's own definition, so use it unless you can state why another weight suits the question.
Rank trackers use a different definition
A rank tracker reports the position of one URL for one keyword at one location and device at one moment. Search Console averages real impressions across all of those. The two numbers will not match, and neither is wrong. Do not mix them in one weighted average.
Checklist for any position number you publish
- State the grain of the source rows (date, query, page, device, country).
- State the segment, so readers know the query population is fixed.
- Compute from additive parts and divide at the end.
- Leave periods without impressions empty.
- Show impression buckets or total impressions beside the average.
Exercise
A query has these daily rows: Day 1 has position 4.0 and 200 impressions, Day 2 has position 12.0 and 600 impressions, Day 3 has position 2.0 and 200 impressions. Calculate the simple mean and the impression-weighted average position for the three days. Which one should you report, and why?
Show answer
The simple mean is (4 + 12 + 2) / 3 = 6.0. The weighted average is (4×200 + 12×600 + 2×200) / 1000 = (800 + 7200 + 400) / 1000 = 8.4. Report 8.4. Day 2 supplied 60% of the impressions, so most searchers saw the result near position 12, and the simple mean hides that. The weighted value is also what Search Console would return for the three days combined.
Exercise
Last month your site-wide average position moved from 9.1 to 14.6, while clicks rose 12%. Name one likely cause, and say what you would check before reporting a ranking decline.
Show answer
A likely cause is mix shift: new or growing long-tail queries added many impressions at low positions, which pulls the weighted average down even though established queries held or improved. Check the position of a fixed segment (for example the top 100 queries by clicks from the earlier period), and compare the share of impressions in position buckets (1–3, 4–10, 11–20, 21+). If the fixed segment is stable and the lower buckets grew, visibility expanded and rankings did not decline.