Skip to content

Analyses

An analysis answers one question a charity asks of its own data. You give it a table, say which column is which, and it joins your data to UK open data and returns figures you can check and reuse.

Kindtech Evidence is built on these analyses. This page is about running them from Python. You can also run them from the command line, or from a chat assistant through the connector.

These analyses follow work first done by DataKind UK volunteers with charities. The case studies reproduce five of those projects.

Every analysis returns the same things:

  • an answer: one or two sentences that answer the question, and the three figures to show first
  • figures: the headline numbers
  • tables: totals behind the figures
  • a map description: which areas to draw and what to colour them by, when the analysis has a map
  • chart descriptions: which table and columns to draw as a bar chart
  • the working: each step taken, with how many rows went in and came out, the figures before rounding and the code that runs it again
  • choices: what the analysis decided for you, and the option that changes it
  • checks: what a person must confirm before using the figures
  • caveats: what the figures cannot say
  • sources: publisher, edition, licence and link for every dataset used
  • a privacy summary: what was hidden, and what left your machine

A result holds totals only. Nothing in it describes one person, and no value from your data is repeated back, not even in a warning or an error message.

Quick start

import pandas as pd
from uk_open_data.analyses import run_analysis

clients = pd.read_csv("clients.csv")

result = run_analysis(
    "reach-deprivation",
    clients,
    columns={"postcode": "Client postcode"},
)

result.answer                                   # the question, answered in a sentence
result.figure("share_most_deprived_20").value   # 41.3 (per cent)
result.table("by_decile").to_frame()            # pandas or polars DataFrame
[check.question for check in result.checks]     # what to confirm first
result.to_dict()                                # everything, as plain JSON types

data can be a pandas or polars DataFrame, or a list of row dictionaries. columns maps each role the analysis needs to one of your column names. You can leave a role out when your data already has a column with that name.

To run an analysis on a file without writing Python, use the command line.

Functions

list_analyses()

Returns an AnalysisInfo for every analysis: its id, title, the question it answers, a summary, its roles (the columns it can use), its input_modes (the shapes of data it accepts), its options, its coverage, and has_map, which is False for an analysis that has no map yet.

Every option has two names. name is its code name, the one a call is written with, such as catchment. label is its short plain name, such as "Area you serve". Show the label beside the option. Every message that points a person at an option uses the label, in quotes ("Change 'Area you serve' to include them."), and never the code name, so the sentence matches what is on the screen. An option has the same label in every analysis that has it, and the result's choices use the same label for the choice it made:

name label
catchment Area you serve
catchment_min_share Share that makes a place part of your area
suppress_below Smallest count shown
postcode_lookup Where postcodes are looked up
need People you are trying to reach
top Places listed
characteristic What people are grouped by
groups How your labels match census groups
mode How people travel
under_represented_below What counts as under-represented
within_km Distance within reach, in kilometres

The area an analysis looks across has one name wherever a person reads it: "the area you serve". catchment is only its code name.

A table's columns have plain names too. table.columns holds the ids, which a program reads, and table.headings maps each id to the heading to show, such as "Your people per 100 in need" for people_per_100_in_need. table.units gives the unit of each column that has one, named as the units of figures are: "percent" or "km". Show a table with its headings and units and it reads the same on a page, in a chat and on the command line. A place is a "Local authority" in most tables and a "Neighbourhood" in the one behind the first analysis's map.

An option that takes one of a fixed list of values lists them as choices, each with a value and a label a person can read, so a page can show a list to pick from. choices is empty when the option is free, such as a number or a place name. For the need option the choices are the built-in needs; a table of your own is still given as a mapping.

A role with reported set to True holds names the result uses too, such as local authorities, so the same names can appear in the result. Values of every other role are never repeated.

A reported role can also list reported_values. That is for a column that holds a person's own words as well, such as their ethnic group: only the listed values are names the result uses, and no other value in the column is ever repeated. If you check a result for values repeated from the input, leave out the listed values when there are any, compared without case, and check every other value in the column. Leave the whole column out only when the role is reported and lists no values.

A role with amount set to True holds a number the analysis adds up: a count of people or a volume. A total of it is in the result, so where one row is the only one for its place or group, that row's number comes back as the total. That is not a repeated value. A number in any other role, such as a latitude, never comes back.

describe_analysis(analysis_id)

Returns the AnalysisInfo for one analysis. Raises KeyError for an unknown id.

run_analysis(analysis_id, data, columns=None, options=None)

Runs an analysis and returns an AnalysisResult.

Raises AnalysisInputError (a ValueError) when the data, the column mapping or an option cannot be used. The message is written for a person and error.problems lists each problem separately.

error.option is the code name of the option the error is about, and error.role the name of the column role, so a page can mark the right box and a program need not search the sentence. When the problems are about several, it is the first of them. Each is None when the error is about neither, for example when a source could not be read. The command line adds what to type: "On the command line this is --option catchment=VALUE."

When the columns an analysis needs were not all found, error.role is the first one still to be named. When an option was given that the analysis does not have, the message lists each option it does have by both names: "need ('People you are trying to reach')".

When a public data source the analysis needs cannot be reached, the requests.RequestException is let out. Its text holds the whole web address that was asked for, which can hold a postcode, so show a message of your own rather than the text. The command line names the site alone, and says whether the source could not be reached, answered with an error, or answered that it does not hold what was asked for, which asking again will not change. A source of need figures that answers that its page or file is not there, as when a publisher moves its tables, is different: asking again will not help, so the analysis raises an AnalysisInputError about need that says where the figures are published. An analysis needs no network when the public figures it uses are kept on your machine: download_datasets() keeps them all.

record_run(analysis_id, input_mode, door)

Records that a run has given a person an answer, so that a host can count how often each analysis is used. It writes one record at INFO level to the uk_open_data.runs logger, and that is all it does: the package adds no handler and sends nothing anywhere. On a person's own machine nobody collects the records. A host that keeps its logs can count them.

from uk_open_data.analyses import record_run

record_run(result.analysis_id, result.input_mode, "page")
# run analysis=reach-deprivation mode=postcodes door=page

run_analysis never records a run by itself. Whatever gives the answer to a person calls record_run once, after the answer has been given: the command line does ("cli"), and a page ("page") or a chat assistant ("chat") built on these analyses should. A run that fails is not recorded.

The record holds the three words and nothing else. Each must be on a fixed list (a registered analysis, one of its input modes, one of the three doors), so no word from a person's data can reach a log. A word that is not on its list raises KeyError (the analysis) or ValueError (the mode or the door), and the message does not repeat it. The same three words are on the record as record.analysis_id, record.input_mode and record.door.

A host that keeps the records imports the logger's name, and the doors, from the package, so neither is typed out a second time:

import logging

from uk_open_data.analyses import DOORS, RUNS_LOGGER

logging.getLogger(RUNS_LOGGER).setLevel(logging.INFO)

Drawing the map

A result describes its map; render_map draws it as an SVG picture with a key and the credits the data licences ask for.

from uk_open_data.analyses import render_map

svg = render_map(result)                  # the first layer: deprivation decile
svg = render_map(result, layer="people")  # people reached, in bands

with open("map.svg", "w", encoding="utf-8") as handle:
    handle.write(svg)

The picture is drawn from the result's own table of totals, so it shows nothing the result does not already hold. People are shown in bands, and the lowest band includes zero. Hover over an area in a browser to see its name and value. The colours adapt to a dark page.

A picture shows one layer, and its title says what the colour shows: "People reached, by neighbourhood". The first layer of a map is drawn in blue and the second in orange, so two pictures of one result do not look like the same measure. The shaded areas sit in a frame with a scale line. Up to twelve local authorities are named one by one; neighbourhoods are named by the local authority they are in. A name that would cover most of a small place is written beside it, where there is room, so its colour can be seen. Text is broken into lines to fit the width you ask for.

The places around the map are drawn in pale grey, with their names where a name fits, when you give their outlines. Only the part of each that the frame shows is written to the picture, so a large neighbour does not make the file large. Put them among the features of boundaries, or in a list under "surroundings". Codes listed under "focus" are the surrounding places that hold the shaded areas: each gets a darker line and its name. Codes listed under "shore" are surrounding places whose outline is where the land ends. The shaded areas are drawn no further than it, and the picture is framed on it. Use it when the outlines of the areas run out over water and the outline of the place that holds them does not.

The outline of a place on a coast can hold a rock or a bank some way off the shore. A part of a place with less than a thousandth of the area of its largest part does not set the frame or move a name, so the place stays in the middle of the picture. Such a part is still drawn when the frame shows it.

The darker line round a place listed under "shore" is dark only where another place's land is beside it. Along water it is a thin grey line, so a tidal river that runs through a place is two thin banks and does not read as a border that splits the place. Land is beside the line when the edge of another place is within a dot and a half of it, or 25 metres on the ground when that is more. Codes listed under "fine" are the places whose outlines are in fine detail. A place that is not listed is taken to be simplified to 200 metres, which does not sit on the line, so it counts from 200 metres. A place that is not listed under "shore" keeps a dark line all round.

boundaries = {
    "type": "FeatureCollection",
    "features": areas,           # outlines you already have
    "surroundings": nearby,
    "focus": ["E09000023"],
    "shore": ["E09000023"],
    "fine": ["E09000023", "E09000011"],
}
svg = render_map(result, boundaries=boundaries)

render_map fetches the outline of each area from the ONS Open Geography Portal. Only the public area codes of the area you serve, and of the local authorities near it, are sent. To draw without the network, pass boundaries= a GeoJSON FeatureCollection you already have; load_map_boundaries(result) fetches one you can save and reuse.

load_map_boundaries fetches the places around the map as well, and lists under "focus" the local authorities that hold a map's neighbourhoods. A map of up to 1,000 neighbourhoods or 20 local authorities is drawn large, so its outlines come from the full ones with detail finer than 10 or 20 metres left out. So do the local authorities that hold its neighbourhoods, and the other places a picture of the usual width shows when there are no more than 40 of them, so that neighbours meet. A place further off keeps its 200 metre outline.

The full outlines of local authorities stop at the shore. The only full outlines of neighbourhoods that are open run out to low water and to the middle of a river. So on a map of neighbourhoods the local authorities that hold them are also listed under "shore", and a river or a bay is left clear. When the fine outline of one of them does not come, nothing is listed and the neighbourhoods are drawn whole. The places whose fine outlines did come are listed under "fine".

A map of more areas is drawn small and takes outlines simplified to 200 metres. Every map asks for every local authority at 200 metres, nearly three megabytes, to find the ones near it. That answer is kept in memory for the life of the process, so a second map does not ask again; uk_open_data.analyses.maps.clear_outline_cache() forgets it. When the places around cannot be fetched, the map is drawn without them and nothing is said.

The fine outlines usually come in a few seconds. At times the service has taken from a quarter of a minute to a minute or two for one map, and it is not known why. A program that cannot wait, such as one answering in a chat, calls load_map_boundaries(result, fine=False). It then gets the 200 metre outlines of every area, and the places around from the answer kept in memory, in a second or two. load_map_boundaries is safe to call from two threads at once.

The answer

result.answer is one or two sentences that answer the question the analysis asks, for example:

Of your people in the area you serve, 49.0% live in the 20% most deprived neighbourhoods in England. Of everyone who lives in that area, 20.0% do, so you reach those neighbourhoods more than their share.

Open with it wherever you show a result, so a report, a page and a chat assistant all say the same thing. It is built from the figures and tables of the result, after small counts are hidden, so it says nothing the result does not already show. When the figure it rests on is hidden, it says so instead of giving a number. The places and groups it names are the public names in the result's tables, never text from your data.

The sentence is careful about what it calls a gap. A place is named as one to look at first only when it falls below the rate for the whole area, so a list of one or two places does not present the place you reach most as a gap, and a place whose count is hidden is not named. A count of every resident is called "residents", not "people in need". A group with nobody in your data is named last, with a line saying so, because it may be a group you do not record.

result.key_figures holds the ids of up to three figures to show first, in order. Each is a figure of the result, and none is hidden: when a figure that would be shown first is hidden to protect a small count, the next one takes its place.

for figure_id in result.key_figures:
    figure = result.figure(figure_id)
    print(figure.label, figure.value, figure.unit)

Checking a result and running it again

A result shows its working, so that anyone can check it or run it again.

result.working lists each step in plain words, with how many rows went in and came out. result.sources gives each source and its date.

A share or a rate is rounded before it is shown. figure.exact is the value before rounding:

figure = result.figure("share_most_deprived_20")
figure.value   # 68.6
figure.exact   # 68.57142857142857

exact is None for a count, which is not rounded, and for a figure that is hidden to protect a small count. It is also None for a distance from one place to a site, which is rounded to the kilometre on purpose so that it says less about where a site is.

result.code is the Python that runs the analysis again with the same settings:

print(result.code)
# Version 0.1 of this analysis, run with
# uk-open-data 0.2.0. This runs it again with
# the same settings. No row or heading of your table is written
# here: put the name of your own column beside each role.
import pandas as pd

from uk_open_data.analyses import run_analysis

data = pd.read_csv("your-table.csv")
result = run_analysis(
    "reach-deprivation",
    data,
    columns={
        "postcode": "",  # the name of your column
    },
    options={
        "suppress_below": 10,
        "postcode_lookup": "auto",
        "catchment_min_share": 0.05,
    },
)
print(result.answer)
for figure in result.figures:
    print(figure.label, figure.value)

It prints the answer and every figure, to set beside the ones in the result.

Every setting that has a value is written out, the ones you left alone too, so the code gives the same result if a default changes in a later version. That is why it can hold a setting the list of choices in a result does not mention. A setting the analysis works out for itself, such as the area you serve when you named none, is left out. An area you named is written as you gave it.

The setting for where postcodes are looked up is written as it was used. Code copied from a run that kept postcodes on one machine says so, and on another machine it stops and asks for the postcode table before it sends a postcode anywhere.

The code holds no row and no heading of your table. The names of your columns are left for you to fill in, because a heading can hold something private. A setting that holds your own words, such as your own labels for groups in who-we-miss, is written as {} with a note to fill it in. So the code is as safe to share as the result is.

The command line prints both as the last two parts of its report, under "Figures before rounding" and "To run it again in Python". The code starts at the margin, so it runs as it is copied.

Charts

result.charts describes the charts a result is best shown with, so a page can draw them without knowing the analysis. Each Chart names a table of the result, the column that names each group of bars (category_column) and one or more series, each a column with a label and a unit. Every series in a chart has the same unit, so one axis serves them all.

chart = result.charts[0]
frame = result.table(chart.table).to_frame()
frame.plot.bar(x=chart.category_column, y=[s.column for s in chart.series])

A value hidden to protect a small count is None in the table. Draw no bar for it.

Small counts

A count from 1 to 4 that is about a named place or a group is returned as None, with suppressed set to True, and so is anything worked out from it. When hiding one cell would let it be worked out from a total, a second cell is hidden with it. So a hidden count is not always small: do not report a hidden cell as "fewer than 5". Every result says this in its privacy notes. Change the threshold with the suppress_below option; it cannot go below 3.

The people a result leaves out are counted like any group: those who live outside the area you serve, those who could not be placed, and, when the groups are people's own labels, those matched to no group. When fewer than 5 are in one of them, the warnings and the working say "fewer than 5", never the number. A total that would give the number away when taken from another, such as people_located or people_supplied, is None, with suppressed set to True and a note that says why. The total the figures are about is always shown.

A result says which threshold was used in privacy.suppress_below. The analyses about sites, provision gap and access and distance, hide nothing, and for them it is None.

Reach against deprivation

reach-deprivation answers: are we reaching people in the most deprived neighbourhoods? It covers England and Wales, on 2021 neighbourhoods (LSOAs), using each nation's own index: the English Indices of Deprivation 2025, or the Welsh Index of Multiple Deprivation 2025.

Each nation ranks only its own neighbourhoods, so an English decile and a Welsh decile are not the same measure. A result therefore covers one nation:

  • the nation of the area you serve, when catchment names it ("England" or "Wales") or names local authorities in it;
  • otherwise the nation where most of your people were placed.

People placed in the other nation are left out, and a warning says how to run the analysis again for them. Naming local authorities in both nations is an input problem. Scotland and Northern Ireland are not covered.

In Wales, the residents of each neighbourhood are the mid-2022 small-area estimates from Nomis, the year England's index uses.

It accepts two shapes of data:

Input mode Columns What it is
postcodes postcode One row per person or case, with a home postcode
neighbourhood_counts lsoa_code, count Already totalled by 2021 LSOA

In postcodes mode the analysis looks postcodes up in the postcode table on your machine when one is installed, and then no postcode is sent anywhere. Install it once with uk-open-data postcodes download. Without the table, the distinct, well-formed postcodes are sent to postcodes.io; no other column leaves your machine, and rows that are blank or not shaped like a postcode are never sent. The result says which happened, under choices and privacy. In neighbourhood_counts mode nothing leaves your machine.

The deprivation index is downloaded from gov.uk, or read from a copy kept on your machine when there is one. A result that used a copy says so in its sources and its working, with the note the copy was kept with.

The analysis then works out the area you serve: the local authorities that each hold at least 5% of the people it could place. The decile figures and the map are about the people who live there, so they can be set against everyone who lives there. People outside the area you serve are counted in the local authority table, and a warning says how many there are.

The people left out are counted like any group. When fewer than 5 live outside the area you serve, or fewer than 5 could not be placed, the warnings and the working say "fewer than 5". people_located and people_supplied are then hidden when taking one total from another would give that number away. When people_located is hidden, so are the unnamed row of the local authority table and the shares in that table, because they would give it away too. people_in_catchment is always shown, because the decile figures are about those people.

Figure Meaning
people_supplied People in the data you gave
people_located People placed in an English (or Welsh) neighbourhood
people_in_catchment People who live in the area you serve
share_most_deprived_10 Share of them in the 10% most deprived neighbourhoods in England (or Wales)
share_most_deprived_20 Share of them in the 20% most deprived neighbourhoods in England (or Wales)
catchment_share_most_deprived_20 Share of residents of the area you serve who live in those neighbourhoods, for comparison
reach_per_1000_most_deprived_20 People reached per 1,000 residents of those neighbourhoods
reach_per_1000_elsewhere People reached per 1,000 residents in the rest of the area you serve

The chart people_by_decile sets the share of your people in each decile against the share of residents of the area you serve.

Table Rows
by_decile One per deprivation decile: people, share of people, residents, share of residents, people per 1,000
by_local_authority One per local authority; authorities outside the area you serve with few people share one unnamed row
by_neighbourhood One per neighbourhood in the area you serve: decile, residents, and people in bands. This feeds the map
Option Default Meaning
suppress_below 5 Counts above zero and below this are hidden
postcode_lookup "auto" "offline" uses the table on your machine and fails without one, "online" uses postcodes.io, "auto" uses the table when it is installed
catchment worked out A local authority name or code, a list of them in one nation, or "England" or "Wales". A council's code from any year finds it, as in need against reach
catchment_min_share 0.05 The share a local authority needs to join a worked-out area
result = run_analysis(
    "reach-deprivation",
    clients,
    columns={"postcode": "Client postcode"},
    options={"catchment": ["Lewisham", "Greenwich"]},
)

Before you use the figures

Read result.checks and result.caveats. Deprivation is measured for neighbourhoods, not people: someone who lives in a deprived neighbourhood is not necessarily deprived.

Reach against connectivity

reach-connectivity answers: are we reaching people in the least-connected neighbourhoods? It sets your people against the Department for Transport's transport connectivity metric: how easily people in each 2021 neighbourhood (LSOA) of England and Wales can reach work, education, healthcare, leisure and community places, shops and other homes. It works like reach against deprivation, with connectivity fifths in place of deprivation deciles.

The least-connected fifth. DfT publishes scores, not groups. So the analysis ranks every neighbourhood of England and Wales by its overall score for one way of travelling, lowest first, and cuts them into five groups of as many neighbourhoods. Fifth 1 is the least connected. Neighbourhoods with the same score go in the same fifth, the lower one, so fifth 1 can hold a few more than a fifth. The working and the least_connected choice say how many it holds. Because one ranking covers both nations, a fifth means the same in England and in Wales, and one result can cover both.

The way of travelling is the mode option: "walking", "cycling", "public_transport" (the default), "driving" or "all_modes". DfT's notes say to compare a score with the same score elsewhere, not one way of travelling with another, so a result uses one.

Names, councils and residents of each neighbourhood come from the indices of deprivation, as in reach against deprivation: the English Indices of Deprivation 2025, and for Wales the Welsh Index of Multiple Deprivation 2025 with Nomis's mid-2022 residents. Only the nations your people were placed in, or that the area you serve names, are read, so an English charity downloads nothing Welsh. The connectivity scores are downloaded from gov.uk, or read from a copy kept on your machine. A result that used a kept copy, of the scores or of an index, says so in its sources and its working.

People are placed, counted and hidden as in reach against deprivation, with the same input modes and the same rules for the area you serve and for small counts. People in Scotland and Northern Ireland are left out, with a warning.

Figure Meaning
people_supplied People in the data you gave
people_located People placed in a neighbourhood of England or Wales with a score
people_in_catchment People who live in the area you serve
share_least_connected_20 Share of them in the least-connected fifth of neighbourhoods
catchment_share_least_connected_20 Share of residents of the area you serve who live in those neighbourhoods, for comparison
reach_per_1000_least_connected_20 People reached per 1,000 residents of those neighbourhoods
reach_per_1000_elsewhere People reached per 1,000 residents in the rest of the area you serve

The chart people_by_fifth sets the share of your people in each fifth against the share of residents of the area you serve.

Table Rows
by_fifth One per connectivity fifth: people, share of people, residents, share of residents, people per 1,000
by_local_authority One per local authority; authorities outside the area you serve with few people share one unnamed row
by_neighbourhood One per neighbourhood in the area you serve: fifth, residents, and people in bands. This feeds the map
Option Default Meaning
suppress_below 5 Counts above zero and below this are hidden
postcode_lookup "auto" As in reach against deprivation
mode "public_transport" The way of travelling the neighbourhoods are ranked by
catchment worked out A local authority name or code, or a list of them, in England and Wales, or "England", "Wales" or "England and Wales"
catchment_min_share 0.05 The share a local authority needs to join a worked-out area
result = run_analysis(
    "reach-connectivity",
    clients,
    columns={"postcode": "Client postcode"},
    options={"mode": "public_transport", "catchment": ["Cumberland"]},
)

Before you use the figures

Read result.checks and result.caveats. Connectivity is measured for neighbourhoods, not people: how easily someone gets about also depends on cost, disability and whether they have a car. The scores are DfT's model of journeys in October to December 2024, which DfT calls experimental statistics, and they say nothing about reaching your own service.

Need against reach

need-reach answers: where is need high and our presence low? It covers England and Wales, by local authority, and is the method of the Smart Works case study turned into a function.

It accepts two shapes of data:

Input mode Columns What it is
postcodes postcode One row per person or case, with a home postcode
area_counts local_authority, count Already totalled by local authority, named or coded

Postcodes are placed as in the first analysis: on your machine when the postcode table is installed, and with postcodes.io otherwise.

Councils whose code changed. The analyses compare places in today's council codes, those of 2025: see Council codes. Figures given by an older code are moved to today's, and councils that merged are added up. The 2021 Census tables are published for the councils of 2023, so Barnsley's and Sheffield's figures move to the codes they took on 1 April 2025 (E08000038 and E08000039). A council you give by an older code or name, in your data or in the area you serve, is taken as today's: Allerdale counts as Cumberland. A council's name is matched on the words that tell councils apart, so "Lewisham Council" and "London Borough of Lewisham" both find Lewisham, and "Aberdeen City Council" finds Aberdeen City. "London" alone is not the City of London. A council or a nation the figures do not cover, such as one in Scotland, is named as such, rather than taken to be spelt wrong. A council that any older part has no figure for is left out whole, never part-counted. When the figures compared move, the working says which and the result cites ONS's Code History Database.

The analysis loads a count of people in need in every local authority, from Nomis, from MHCLG's homelessness tables, from DESNZ's fuel poverty statistics, from DWP's children in low income families or from UKHSA's childhood vaccinations or from ONS's police recorded crime, divides the people you helped in each one by it, and lists the high-need local authorities where you reach the fewest people per 100 in need. A local authority is high need when its count is in the top quarter of the area you serve. With fewer than four places, the one with the largest count is high need.

Choose the need with the need option:

need People counted
"unemployed" (default) Unemployed people aged 16 to 64, not counting full-time students, Census 2021
"unemployed_women" Unemployed women aged 16 to 64, not counting full-time students, Census 2021
"unemployed_men" Unemployed men aged 16 to 64, not counting full-time students, Census 2021
"residents" Everyone who lives there, of every age, Census 2021. Use it when what you offer is for anyone
"owed_a_homelessness_duty" Households a council assessed as owed a homelessness prevention or relief duty in the latest quarter, England only, from MHCLG
"in_temporary_accommodation" Households in temporary accommodation on the last day of the latest quarter, England only, from MHCLG. A household placed in another council's area is counted by the council that placed it
"households_in_fuel_poverty" Households in fuel poverty in one year, England only, from DESNZ. Modelled estimates, published as Official Statistics in Development
"children_in_low_income_families" Children under 16 in relative low income families, before housing costs, in the latest financial year, England and Wales, from DWP. This is DWP's headline measure
"children_in_low_income_families_after_housing_costs" The same children, with income counted after housing costs, so more children count where housing costs more, from DWP
"children_without_mmr1_by_2" Children who turned 2 in the latest year, April to March, without a first dose of the measles, mumps and rubella (MMR) vaccine, England only, from UKHSA. Published for upper-tier councils and shared out to councils
"children_without_mmr2_by_5" Children who turned 5 in the latest year without both doses of MMR, England only, from UKHSA. Published for upper-tier councils and shared out to councils
"recorded_crime" Offences the police recorded in the latest year, excluding fraud, England and Wales, from ONS. Published for community safety partnerships and shared out to councils
"violence_against_the_person" Offences of violence against the person the police recorded in the latest year, England and Wales, from ONS. Published for community safety partnerships and shared out to councils
{"dataset": ..., "label": ..., "filters": {...}} Any table Nomis publishes by local authority. The filters are the category codes to add up. Counts are asked for (measures 20100) unless the filters name another measure

The three unemployment needs count the census group "Economically active (excluding full-time students): Unemployed", as the case study does. Full-time students who were looking for work are a separate census group and are not counted. To count them too, give the table form with both groups:

options = {
    "need": {
        "dataset": "NM_2124_1",
        "label": "Unemployed people aged 16 to 64, with full-time students",
        "filters": {
            "c2021_eastat_7": [2, 4],
            "c_sex": 0,
            "c2021_age_7": [2, 3, 4, 5],
        },
    }
}

The two homelessness needs count households, not people, so the result says "households in need" and sets the people you helped per 100 households. Read that as more or less reach between places, not as a share. They are the latest quarter MHCLG has published, and the result cites the quarter. A council that sent MHCLG no figures for the quarter, or whose figure MHCLG held back, is left out of the comparison, never counted as none, and the result names those councils in a warning. Naming one in catchment is an input problem that says so.

The fuel poverty need counts households too, in the same way. Its figures are DESNZ's modelled estimates for one year, by the Low Income Low Energy Efficiency measure, and the result cites the year. DESNZ publishes them as Official Statistics in Development, for general patterns and to find places of particularly high or low fuel poverty, and the result's caveats say so.

The two low income needs count children under 16 in families whose income is below 60% of the UK's median that year, so the result says "children in low income families" and sets the people you helped per 100 of them. Read that as more or less reach between places too. DWP counts a family only if it claimed Child Benefit and Universal Credit, tax credits or Housing Benefit during the year, so a family on low income that claimed none of these is missed. They are the latest financial year DWP has published, and the result cites it, such as "FYE 2025". DWP gives councils their codes of April 2023, and Barnsley's and Sheffield's figures move to today's codes.

The two vaccination needs count children not vaccinated against measles, mumps and rubella: those who turned 2 during the year without a first dose, or turned 5 without both. They are UKHSA's children who reached the age less those vaccinated, so the result says "children without a first MMR dose" or "children without both MMR doses", never "not vaccinated" for a child with one dose, and sets the people you helped per 100 of them. They are the latest year UKHSA has published, April to March, and the result cites it. UKHSA publishes them for upper-tier councils, so they are shared out to councils, as below. UKHSA counts the City of London in Hackney's figures, the Isles of Scilly in Cornwall's and Rutland in Leicestershire's, so each pair's figure is shared out as one area, by residents. UKHSA says the children recorded are uncertain where people move often, as in London, so coverage there may be underestimated, and the children not vaccinated overcounted.

The two crime needs count offences, not people or victims: one person can be the victim of many offences, and many offences have no one victim. So the result says "offences recorded" and sets the people you helped per 100 offences. Read that as more or less reach between places, not a share of anyone. An offence is counted where it was recorded, and forces record crime in different ways. They are the latest year ONS has published, and the result cites it, such as "year ending June 2026". ONS publishes them for community safety partnerships, most of them one council, so they are shared out to councils, as below. Offences the police could not place in a partnership are left out, and so is a partnership whose figures ONS marks as incomplete, such as five in Kent today: the warning names them and their councils.

Need figures for bigger areas. Some figures are published for areas bigger than a council: upper-tier councils (counties), community safety partnerships or police force areas. A need from one of these is shared out to the councils in it, so the analyses still compare councils. This was decided in #210, which also says what it costs and when to think again.

  • Each council takes its share of the area's count by its share of the area's residents at the 2021 Census, rounded to whole people, households, children or offences, as the need counts them, from local_authority_lookup.
  • A council made of whole areas takes their figures as published. A unitary council is a whole upper-tier council, and Buckinghamshire is four whole partnerships.
  • The others' figures are estimates. They take the count to be spread like the residents, so councils in one county differ only by how many people live in them.
  • A council with any part in an area the figures have no figure for is left out, never part-counted. The warning names the area and the council.
  • An area the source counts in another's figures, such as the City of London in Hackney's, shares that figure with it as one area, by residents. A need defined in code lists such areas with Measure.included_in. If the figures give the area a figure of its own, it takes that.
  • The working says how many areas the figures were for and how they were shared, and the result cites the lookup.

Only counts are shared. A rate, such as the share of children vaccinated, is turned into a count first where its source gives the number it is a share of: children not vaccinated are the children less those vaccinated. A rate without that number isn't supported yet. The two vaccination needs are published for upper-tier councils. A need defined in code says which kind of area its figures are for with Measure.area.

The need figures are public. They are fetched once for each need and then kept in memory for as long as the program runs; clear_need_cache() forgets them. To run with no request to Nomis at all, keep a copy on the machine, in the same data folder as the postcode table:

from uk_open_data.analyses.need_reach import download_need_figures, keep_need_figures

download_need_figures("unemployed")   # fetch once, when a server is built
download_need_figures("residents")    # so the map can shade need by its rate
download_need_figures("in_temporary_accommodation")  # keeps the quarter too

# or keep figures of your own under a built-in need, for a demonstration
keep_need_figures(
    "unemployed",
    [("E09000023", "Lewisham", 9000), ("E09000011", "Greenwich", 8000)],
    note="invented for a demonstration.",
)

A result that used a kept copy says so in its sources and its working, with the note the copy was kept with. download_datasets() keeps every built-in need at once, with everything else the analyses use, and clear_caches() forgets what every dataset fetched.

The area you serve should hold the places you do not reach yet as well. Name it with catchment: a list of local authorities, or a country. When you leave it out, the analysis works the area out as the first analysis does: each local authority that holds at least 5% of the people located (catchment_min_share). When none does, every local authority the need figures cover is compared.

Each need says which nations its figures cover. The census needs, and any Nomis table you give, are read for England and Wales. A need that covers only England, such as the homelessness and fuel poverty ones, leaves out the people placed in Wales and names the whole area "England". Naming "Wales" or "England and Wales" as the area for it is an input problem.

An area worked out this way holds only places you already reach, so it can show where your reach is low against need but not where you reach nobody. The result says so in a warning. To see the places you do not reach, name the area.

Figure Meaning
people_supplied People in the data you gave
people_located People placed in a local authority in England or Wales
people_in_catchment People who live in the area you serve
areas_compared Local authorities compared
people_in_need People in need in the area you serve
reach_per_100_in_need People you reached per 100 people in need, across the area
high_need_areas Local authorities with high need
high_need_areas_without_people High-need local authorities where you reached nobody
share_of_people_in_high_need_areas Share of your people who live in high-need local authorities
share_of_need_in_high_need_areas Share of people in need who live there, for comparison

The charts need_in_priority_areas and reach_in_priority_areas show people in need and people reached per 100 in need for the places in priority_areas.

The labels follow the need. When the need is every resident, the figures, the headings, the list, the working and the source say "residents" and "the local authorities with the most residents", not "people in need" and "high need". The fourth and fifth analyses do the same.

The answer says so when the area was worked out from your data: it opens "In the 7 local authorities where most of your people live". When a fifth or more of the people in your data could not be placed in the area you serve, it ends by saying how many are not counted. When some of them could not be placed in any local authority, which is a name or a postcode to put right, and others live outside the area, which is not a mistake, it says how many of each.

The people left out are counted like any group. When fewer than 5 live outside the area you serve, or fewer than 5 could not be placed, the warnings and the working say "fewer than 5". people_located and people_supplied are then hidden when taking one total from another would give that number away. people_in_catchment is always shown, because every figure is about those people. The answer goes by the totals that are shown.

When only one local authority is compared every share is 100%, so key_figures names the rate and the two counts behind it instead: reach_per_100_in_need, people_in_catchment and people_in_need.

Table Rows
priority_areas The high-need local authorities, your lowest reach first: people in need, people, people per 100 in need. It is a list in that order and no more: a place on it can have more reach than the area as a whole
by_local_authority One per local authority compared, with need and reach in bands, and people in need for each 1,000 residents. This feeds the map

The map shades need by its rate, people in need for each 1,000 residents, in five equal groups. With fewer than five places, each is a group of its own, from the lowest group to the highest, and one place alone is in the middle group. The three groups of the reach layer work the same way. The note of a layer says so when its places are fewer than its groups, and says nothing of it otherwise. A count would make the largest places darkest whatever their need. The list of high-need places still goes by the count, as the case study does. The residents are the census count of everyone who lives in each local authority, loaded beside the need figures.

The map falls back to the count in two cases, and the result says which way it went in its choices (map_need) and in the note of the map's need layer. One is when the need is every resident, so there is no rate to work out. The other is when the need figures came from a copy kept on the machine and no copy of the residents is kept beside it: the analysis does not fetch them, so that a run kept off the network stays off it.

Option Default Meaning
suppress_below 5 Counts above zero and below this are hidden
postcode_lookup "auto" As for the first analysis
need "unemployed" The need to compare your reach with
catchment worked out A local authority name or code, a list of them, or "England", "Wales" or "England and Wales"
catchment_min_share 0.05 The share a local authority needs to join a worked-out area
top 10 How many places to list, from 1 to 50
result = run_analysis(
    "need-reach",
    clients,
    columns={"postcode": "Client postcode"},
    options={"need": "unemployed_women"},
)

result.table("priority_areas").to_frame()

A local authority with a hidden count is still ranked. It is ranked as if it had the largest count that would be hidden, which depends on the threshold alone, so the order of the list gives nothing away.

Before you use the figures

Read result.checks and result.caveats. Low reach is not the same as unmet need: another organisation may already serve the place. Need is a count of people, so large local authorities are more likely to be listed.

Who we are missing

who-we-miss answers: who do we reach less than their share of the people who live here? It covers England and Wales, and is the method of the Sobus case study turned into a function.

It accepts three shapes of data:

Input mode Columns What it is
postcodes group, postcode One row per person, with their group and home postcode
group_counts group, count Already totalled by group
people group One row per person, with their group and no location

The group column holds each person's ethnic group, or their sex, in your own words. The analysis matches each label to a group the 2021 Census publishes, counts your people by group, and sets each group's share of your people against its share of the residents of the area you serve. A group is under-represented when its share of your people is below four fifths of its share of residents.

Choose what the column holds with the characteristic option:

characteristic Groups compared Census table
"ethnic_group" (default) Asian, Black, Mixed, White, Other TS021
"sex" Female, Male TS008

Labels are matched by their wording. "Black Caribbean" is Black, "White and Black Caribbean" is Mixed, "Any other ethnic group" is Other, and "Not stated" matches nothing. People whose label matches nothing are counted, left out of the shares, and a warning says how many there are, or "fewer than 5". Codes and short forms cannot be matched by wording, so say where they belong with the groups option:

result = run_analysis(
    "who-we-miss",
    clients,
    columns={"group": "Ethnicity", "postcode": "Client postcode"},
    options={"groups": {"BAF": "Black", "WBR": "White"}},
)

result.table("by_group").to_frame()

The result names the census groups. It never repeats one of your own labels. The group role lists the census group names as its reported_values, because a label of yours can be the same as one of them.

With postcodes the analysis works out the area you serve as the first analysis does: the local authorities that each hold at least 5% of the people it could place. People who live outside it are left out, because they are set against the residents of the area you serve. Without postcodes the analysis cannot tell where you work, so you must name the area with catchment.

The residents come from Nomis, for every local authority at once. They are public, are fetched once for each characteristic and are then kept in memory; clear_residents_cache() forgets them. To run with no request to Nomis, keep a copy on the machine, as for need figures:

from uk_open_data.analyses.who_we_miss import download_residents, keep_residents

download_residents("ethnic_group")   # fetch once, when a server is built

# or keep figures of your own, for a demonstration
keep_residents(
    "sex",
    [("E09000023", "Lewisham", {"Female": 156000, "Male": 144000})],
    note="invented for a demonstration.",
)
Figure Meaning
people_supplied People in the data you gave
people_in_catchment People set against residents: with postcodes, those who live in the area you serve
people_matched People whose label matched a census group. The shares are of these people
people_not_matched People with no label, or one that matched no census group
residents Residents of the area you serve in the 2021 Census
groups_under_represented Groups you reach less than their share of residents
share_of_people_first_group Share of your people in the first of those groups
share_of_residents_first_group Share of residents in that group

The people left out are counted like any group: those matched to no group, those who live outside the area you serve, and those who could not be placed. When fewer than 5 are in one of them, the warnings and the working say "fewer than 5" and people_not_matched is hidden. people_in_catchment and people_supplied are then hidden when taking one total from another would give that number away. people_matched is always shown, because the shares are of those people. When people_not_matched is hidden, residents takes its place in key_figures.

The last two are the two shares the answer quotes, each with its value before rounding. They are there when the answer quotes them: when a group is reached less than its share and has people in your data.

The chart people_against_residents sets the share of your people in each group against the share of residents.

Table Rows
by_group One per census group: people, share of people, residents, share of residents, representation (the first share divided by the second) and whether the group is under-represented
Option Default Meaning
suppress_below 5 Counts above zero and below this are hidden
postcode_lookup "auto" As for the first analysis
characteristic "ethnic_group" What the group column holds
groups none Your label to census group, for labels the wording does not settle
catchment worked out from postcodes A local authority name or code, a list of them, or "England", "Wales" or "England and Wales". Needed when there are no postcodes. A council's code or name from any year is taken as today's, as in need against reach
catchment_min_share 0.05 The share a local authority needs to join a worked-out area
under_represented_below 0.8 A group is under-represented below this fraction of its share of residents

A group with a hidden count is not judged. A group nobody came from has a count of zero, which is shown, and is under-represented.

This analysis has no map yet. The residents are compared across the whole area you serve, not place by place.

Before you use the figures

Read result.checks and result.caveats. A gap is not proof of a barrier: groups differ in age and in need, and the census counts residents of every age. With few people, a gap can be chance. Do not publish two runs with different areas side by side, because a small count can be worked out by taking one from the other.

Provision gap

provision-gap answers: where is provision thin against need across a region? It covers England and Wales, by local authority, and follows the method of the Starlight case study: total what is provided in each place, divide by the people it is for, and look at the places where need is high and provision is thin.

The analysis is about sites and what they provide, not about people. It accepts three shapes of data:

Input mode Columns What it is
sites postcode, volume One row per site or service, with how much it provides
area_volumes local_authority, volume Already totalled by local authority, named or coded
site_list postcode One row per site or service. Each site counts as one

The volume is a number of zero or more: sessions, places, boxes, hours. A row whose volume is not a number stops the run, and the message says how many rows to correct. Postcodes are placed as in the first analysis: on your machine when the postcode table is installed, and with postcodes.io otherwise. Councils are compared in today's codes, as in need against reach.

The analysis loads a count of people in every local authority from Nomis, of households from MHCLG or DESNZ, or of children from DWP, divides the provision in each one by it, and lists the high-need local authorities with the least provision per 1,000 people, households or children. A local authority is high need when its count is in the top quarter of the area you serve, as in the second analysis.

The need option takes the same values as in the second analysis, and the same kept copies (keep_need_figures, download_need_figures) are used. It has no default. The places listed depend on it, so say who your provision is for. "residents", everyone who lives in the place, fits provision that is for anyone, but the places listed are then the ones where most people live. Without a need the run stops with an AnalysisInputError whose option is "need", and its message lists the needs to choose from.

Figure Meaning
volume_supplied Provision in the data you gave
volume_located Provision placed in a local authority in England or Wales
volume_in_catchment Provision in the area you serve
areas_compared Local authorities compared
areas_without_provision Local authorities where you provide nothing
people_in_need People in need in the area you serve
volume_per_1000_in_need Provision per 1,000 people in need, across the area
high_need_areas Local authorities with high need
high_need_areas_without_provision High-need local authorities where you provide nothing
share_of_provision_in_high_need_areas Share of your provision that is in high-need local authorities
share_of_need_in_high_need_areas Share of people in need who live there, for comparison

The charts need_in_priority_areas and provision_in_priority_areas show people in need and provision per 1,000 in need for the places in priority_areas. The map has two layers, provision and need, and opens on provision.

Table Rows
priority_areas The high-need local authorities, thinnest provision first: people in need, volume, volume per 1,000 in need. The labels follow the need, as in the second analysis
by_local_authority One per local authority compared, with need and provision in bands. This feeds the map
Option Default Meaning
postcode_lookup "auto" As for the first analysis
need none, must be given The people to set your provision against
catchment England and Wales A local authority name or code, a list of them, or "England", "Wales" or "England and Wales"
top 10 How many places to list, from 1 to 50
result = run_analysis(
    "provision-gap",
    sites,
    columns={"postcode": "Site postcode", "volume": "Sessions a year"},
    options={"need": "residents", "catchment": "Wales"},
)

result.table("priority_areas").to_frame()

This analysis hides no count, and has no suppress_below option. Provision is what an organisation provides, not a number of people, so every total is shown, however small. Where a local authority holds one site, the provision shown for it is that site's. If your numbers are people, such as people seen at each site, use the need against reach analysis instead, which hides small counts. The result still names no site and repeats no postcode.

The case study compares England's Integrated Care Boards and uses hospital admissions as the need. This analysis compares local authorities and takes the need from Nomis. Health boards, and a need column of your own, are not in it yet.

Before you use the figures

Read result.checks and result.caveats. Thin provision is not the same as unmet need: another organisation may already provide there. Provision is counted where a site is, and people travel. Need is a count of people, so large local authorities are more likely to be listed.

Access and distance

access-distance answers: how far are people from our nearest site, and where would a new site help most? It covers England and Wales, by local authority, and follows the method of the Material Focus case study.

Like the provision gap analysis, it is about sites, not about people. It accepts two shapes of data:

Input mode Columns What it is
site_coordinates latitude, longitude One row per site, in degrees. West is negative
site_postcodes postcode One row per site. Placed on your machine when the postcode table and the centres of neighbourhoods are there

A row whose position is outside the United Kingdom is left out and counted; that is also what happens when the two columns are swapped. A site in Scotland or Northern Ireland still counts as a site.

Site postcodes that stay on your machine

The postcode table holds the neighbourhood of each postcode but no position. So the analysis places a site at the centre of its neighbourhood, from a file of neighbourhood centres kept on your machine. In a town that moves a site by a few hundred metres, and in the countryside by up to a few kilometres; the result carries a caveat that says so. Keep the centres once, when a server is built:

from uk_open_data.analyses.access_distance import download_centres

download_centres("neighbourhood")   # about 35,700 centres, about 1 MB

What happens to site postcodes follows postcode_lookup:

postcode_lookup Postcode table installed No postcode table
"auto" (the default) Placed on your machine. Nothing is sent Sent to postcodes.io
"offline" Placed on your machine. Nothing is sent The analysis stops
"online" Sent to postcodes.io Sent to postcodes.io

With a postcode table installed and no centres kept, the analysis stops and names the function to run. It never falls back to sending postcodes, and it never fetches the centres while an analysis runs. A server that sets "offline" cannot send a postcode. The result says which happened, under choices and privacy.sent_to_third_parties.

The table and the centres cover England and Wales. On your machine, a site with a Scottish or Northern Irish postcode is not found and is left out and counted; give its latitude and longitude instead.

The analysis loads the people in every local authority from Nomis and the centre of every local authority from the ONS Open Geography Portal. For each local authority it measures the distance in a straight line from the centre to your nearest site, to the nearest kilometre. A local authority is within reach when that distance is within_km or less. The list shows the local authorities beyond reach, with the most people first: the places where a new site would bring the most people within reach.

Distance is not travel time. The package has no road or public transport times, so the analysis does not turn kilometres into minutes. And it measures from the centre of a local authority, not from where each person lives, which is rough for a large rural one.

The need option takes the same values as in the second analysis, and the same kept copies. The default is "residents". The centres can be kept on the machine too, so the analysis runs with no request at all:

from uk_open_data.analyses.access_distance import download_centres, keep_centres

download_centres()   # fetch once, when a server is built

# or keep centres of your own, for a demonstration
keep_centres(
    [("E09000023", 51.45, -0.02), ("E09000011", 51.47, 0.05)],
    note="invented for a demonstration.",
)

# the same for the centres of neighbourhoods, which place site postcodes
keep_centres(
    [("E01003189", 51.46, -0.01)],
    note="invented for a demonstration.",
    level="neighbourhood",
)
Figure Meaning
sites_supplied Sites in the data you gave
sites_located Sites placed in the United Kingdom
areas_compared Local authorities compared
people_in_need People in the area you serve
average_distance_km Average distance from the centre of each person's local authority to your nearest site. A place with many people counts for more
share_of_people_within_reach Share of people in a local authority whose centre is within within_km of a site
people_beyond_reach People in a local authority whose centre is farther than that
areas_beyond_reach Local authorities whose centre is farther than that
farthest_distance_km Distance from the centre of the farthest local authority to a site

Every distance is from the centre of a local authority, the one the ONS publishes for it, and every person is counted there. That is coarse. A London borough is a few kilometres across, so 10 km says something about it. A large rural local authority can be 50 km across: a site can be inside it and still be farther than 10 km from its centre, and the place is then listed as far from a site. The answer, the labels, the headings and a caveat all say that distance is from the centre. Where the places you work in are large, set within_km higher and read the distances, not only who is within reach.

The charts people_in_priority_areas and distance_in_priority_areas show the people and the distance for the places in priority_areas. The map has two layers, distance and need.

Table Rows
priority_areas The local authorities beyond reach, most people first: people, distance in kilometres. Empty when every place is within reach
by_local_authority One per local authority compared, with people and distance in bands. This feeds the map
Option Default Meaning
postcode_lookup "auto" How site postcodes are placed. See the table above
need "residents" The people to measure distance for
catchment England and Wales A local authority name or code, a list of them, or "England", "Wales" or "England and Wales". A council's code or name from any year is taken as today's, as in need against reach
within_km 10 How many kilometres from a site counts as within reach
top 10 How many places to list, from 1 to 50
result = run_analysis(
    "access-distance",
    sites,
    columns={"latitude": "Lat", "longitude": "Long"},
    options={"catchment": "Wales", "within_km": 15},
)

result.table("priority_areas").to_frame()

This analysis hides no count, and has no suppress_below option. The result names no site and repeats no postcode or position. Distances are rounded to the kilometre, but the distances from several local authorities can still show roughly where a site is.

Confidential addresses

Do not share a result if the address of a site is confidential, such as a refuge. A check in every result asks this.

Before you use the figures

Read result.checks and result.caveats. The figures say how far people are from a site. They do not say how far the people you see travel, or whether anyone far away needs you.

Writing an analysis

An analysis is an AnalysisInfo and a function that takes an AnalysisInput and returns an AnalysisResult. Register it with register_analysis. The rules every analysis keeps:

  1. Totals, never rows. Report problems by how many rows they affect.
  2. Hide small counts and anything that gives them away. Do not publish two breakdowns that can be taken from each other to get a small count. Say in the privacy notes that a hidden count is not always small.
  3. Give every figure a source.
  4. State every choice and name the option that changes it. Give each option a label, use the label in quotes whenever a sentence points at the option, and pass option= or role= when you raise AnalysisInputError. Give a table headings for any column the package has no heading for.
  5. Leave checks for a person to answer.
  6. List anything sent off the machine in privacy.sent_to_third_parties.
  7. Answer the question in answer, from figures the result shows and nothing else, and name the figures to show first in key_figures.
  8. Give a share or a rate its exact value, from before_rounding, when the figure is shown, and never when it is hidden. Mark an option private when the value a person gives holds words from their own data, so the code that runs the analysis again leaves it out. run_analysis writes result.code for you.