Skip to main content

demography

This package implements a simple mechanism for quickly loading demographic data based on post codes. This is currently only implemented for the UK. It is based on data made available by the UK's Office for National Statistics (ONS).

The data was taken from Geoportal.

Getting started

You can install demography with:

pip install demography

There's only really one main function in this package, and it works like this:

import demography

demography.get("SW1A 0AA", using="groups")

You'll get something like:

['Cosmopolitans', 'Aspiring and affluent', 'Highly-qualified quaternary workers']

These are Classification for Output Areas (OAC) groups -- demographic groupings provided by ONS for specific regions. If a specific OAC group cannot be found from the full postcode, it will default to using the prefix value (i.e. area-level demographics). If this too does not return a value, it will return the value provided by the default parameter.

You can also get the group codes:

demography.get("SW1A 0AA", using="oac")

And you'd get:

2D2

If you want to access the mappings between OAC codes and the groups together, you can use:

demography.groups("uk")

To give:

{'1A1': ['Rural residents', 'Farming communities', 'Rural workers and families'], '1A2': ['Rural residents', 'Farming communities', 'Established farming communities'] ...

Finally, it can be useful to have these groups encoded with:

demography.get("SW1A 0AA", using="encoded_groups")

To give:

[30, 55, 59]

To retrieve the encodings for this, you can use:

demography.encoded_groups("uk")

Validation

As an additional benefit, you can enable validation for postcodes with:

demography.get("SW1A 0AA", using="encoded_groups", validate=True)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

demography-0.0.2.tar.gz (7.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

demography-0.0.2-py3-none-any.whl (7.2 MB view details)

Uploaded Python 3

File details

Details for the file demography-0.0.2.tar.gz.

File metadata

  • Download URL: demography-0.0.2.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.4

File hashes

Hashes for demography-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ca0f7c66683bee7db5b219470d28a7c2d5f30b0ab68135223b3e3c592a20e5c0
MD5 875c6cbca652dc4e4e634c8f08f73d8f
BLAKE2b-256 2f8f764a72323f6c5772c710d8ac0ab7bf98becf8fd439bee7b836898524585d

See more details on using hashes here.

File details

Details for the file demography-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: demography-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.4

File hashes

Hashes for demography-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7773c9b50765ac0efda6e6ecbcbeea66a6567ce7bb3d81f7e5680e0f09a2f368
MD5 ffc68bb0b4f5f73ffda66139bbb8729d
BLAKE2b-256 6c78da03094885b8d332b92a0721e9083c234f6eb0ea40c9a7f124a36b315519

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page