DEV Community

Deepak Shukla
Deepak Shukla

Posted on Edited on

Working with UK off-gas-grid statistics in Python: validate geography before ranking regions

A common mistake in energy-data dashboards is treating every row in a regional dataset as the same geographic level. A national total is not another region, and averaging regional percentages does not reproduce the national estimate unless the denominators happen to be equal.

Here is a small, reproducible example using the 2024 Great Britain domestic gas-grid estimates published by the Department for Energy Security and Net Zero (DESNZ) on 18 December 2025.

1. Read a versioned public data endpoint

The off-gas-grid data hub maintained by our heating information project provides a JSON and CSV transcription of the rounded percentages in DESNZ Chart 17. It is not a new survey. Use the official release for the underlying methodology and detailed data.

Python 3, standard library only:

import json
from urllib.request import urlopen
from statistics import mean

url = (
    "https://infraredheatinginstallers.co.uk"
    "/api/public/data/off-gas-grid.json"
)

with urlopen(url, timeout=15) as response:
    data = json.load(response)

assert data["dataYear"] == 2024, "Review source if data year changes"
rows = data["regions"]
national = [r for r in rows if r["level"] == "national"]
regional = [r for r in rows if r["level"] == "region"]

assert len(national) == 1
assert len(regional) == 11
assert len({r["slug"] for r in rows}) == len(rows)
assert all(0 <= r["offGasGridPercent"] <= 100 for r in rows)

gb = national[0]["offGasGridPercent"]
assert gb == data["averagePercent"]

for row in sorted(
    regional, key=lambda r: r["offGasGridPercent"], reverse=True
):
    print(f'{row["name"]:25} {row["offGasGridPercent"]:2}%')

print("Published GB estimate:", gb)
print("Unweighted regional mean:",
      round(mean(r["offGasGridPercent"] for r in regional), 2))
Enter fullscreen mode Exit fullscreen mode

For the published 2024 values, the highest share is South West England (24%), and the lowest is North East England (7%). Great Britain is 16%. The unweighted mean of the 11 regional shares is approximately 15.64%. That is a different statistic, not a replacement for the official national figure.

2. Avoid turning percentages into unsupported counts

The denominator matters. A region's rounded percentage cannot be converted to an exact count without the underlying domestic property totals and suitable treatment of rounding. Nor can the share establish that a specific home uses oil, electricity or a heat pump.

If you have compatible denominator data, a weighted mean can be useful for exploration:

def weighted_share(shares, property_totals):
    if len(shares) != len(property_totals) or not shares:
        raise ValueError("Supply matching, nonempty series")
    if any(not 0 <= s <= 100 for s in shares):
        raise ValueError("Invalid percentage")
    if any(n <= 0 for n in property_totals):
        raise ValueError("Property totals must be positive")
    return sum(s*n for s, n in zip(shares, property_totals)) / sum(property_totals)
Enter fullscreen mode Exit fullscreen mode

Even then, rounding and methodology differences can prevent an exact match. For an official GB headline, preserve the published national row.

3. Keep the provenance with the data

A production importer should retain the version, data year, source URL, release date and licence. Store a snapshot of the response if you need reproducible historical results. When a new release arrives, validate the regional coverage and compare it with the old snapshot before updating dashboards.

Great Britain here means England, Scotland and Wales; Northern Ireland is not included. The measure covers domestic properties, not commercial buildings, and does not determine an individual property's gas connection.

Sources and reuse

Contains public sector information licensed under the Open Government Licence v3.0. The original statistics are credited to DESNZ. Disclosure: our team maintains the data hub used in this example.

Drafted with AI assistance; source figures and endpoint schema were checked against the live dataset.

Top comments (0)