{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Create region-averaged data\n", "\n", "> This is a copy of notebook 3 (\"Create maps\") with the mapping elements removed.\n", "\n", "Average the data for all LSOAs in a given region to find new values for e.g. population weighted mean IMD score per IVT catchment, or mean transfer time by ambulance trust.\n", "\n", "Most of this notebook involves:\n", "+ Load the data for all LSOAs\n", "+ Pick out only the LSOAs in a given region\n", "+ Average or sum the data for those LSOAs\n", "\n", "Notes:\n", "* Change from Notebook 3: ethnicity now looks at \"white British\" vs. \"other than white British\" groups rather than \"white\" vs \"other than white\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1 Set up" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.1 Import libraries and define file paths" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from dataclasses import dataclass\n", "import geopandas as gpd\n", "import numpy as np\n", "import os\n", "import pandas as pd\n", "from pandas.api.types import is_numeric_dtype" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Define file paths\n", "@dataclass(frozen=True)\n", "class Paths:\n", " '''Singleton object for storing paths to data and database.'''\n", "\n", " data = './data'\n", " collated = 'collated_data_amb.csv'\n", "\n", " hospitals = 'hospitals'\n", " stroke_hospitals = 'stroke_hospitals_2022.csv'\n", "\n", " shapefiles = 'shapefiles'\n", " lsoa_shp = ('Lower_layer_super_output_areas_(E+W)_2011_Boundaries_' +\n", " '(Generalised_Clipped)_V2.zip')\n", "\n", "\n", "paths = Paths()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 1.2 Load data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**LSOA information** - load `collated_data.csv` produced by `01_combine_demographic_data.ipynb` which has information on each LSOA." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | LSOA | \n", "admissions | \n", "closest_ivt_unit | \n", "closest_ivt_unit_time | \n", "closest_mt_unit | \n", "closest_mt_unit_time | \n", "closest_mt_transfer | \n", "closest_mt_transfer_time | \n", "total_mt_time | \n", "ivt_rate | \n", "... | \n", "lsoa_code | \n", "region | \n", "region_code | \n", "region_type | \n", "short_code | \n", "icb | \n", "icb_code | \n", "isdn | \n", "lhb | \n", "icb_lhb | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Welwyn Hatfield 010F | \n", "0.666667 | \n", "SG14AB | \n", "18.7 | \n", "NW12BU | \n", "36.9 | \n", "CB20QQ | \n", "39.1 | \n", "57.8 | \n", "6.8 | \n", "... | \n", "E01033311 | \n", "NHS Hertfordshire and West Essex ICB - 06K | \n", "E38000049 | \n", "SICBL | \n", "HE1 | \n", "NHS Hertfordshire and West Essex Integrated Ca... | \n", "E54000025 | \n", "East of England (South) | \n", "NaN | \n", "NHS Hertfordshire and West Essex Integrated Ca... | \n", "
1 | \n", "Welwyn Hatfield 012A | \n", "4.000000 | \n", "SG14AB | \n", "19.8 | \n", "NW12BU | \n", "36.9 | \n", "CB20QQ | \n", "39.1 | \n", "58.9 | \n", "6.8 | \n", "... | \n", "E01023920 | \n", "NHS Hertfordshire and West Essex ICB - 06K | \n", "E38000049 | \n", "SICBL | \n", "HE1 | \n", "NHS Hertfordshire and West Essex Integrated Ca... | \n", "E54000025 | \n", "East of England (South) | \n", "NaN | \n", "NHS Hertfordshire and West Essex Integrated Ca... | \n", "
2 rows × 128 columns
\n", "\n", " | Postcode | \n", "Hospital_name | \n", "Use_IVT | \n", "Use_MT | \n", "Use_MSU | \n", "Country | \n", "Strategic Clinical Network | \n", "Health Board / Trust | \n", "Stroke Team | \n", "SSNAP name | \n", "... | \n", "ivt_rate | \n", "Easting | \n", "Northing | \n", "long | \n", "lat | \n", "Neuroscience | \n", "30 England Thrombectomy Example | \n", "hospital_city | \n", "Notes | \n", "geometry | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "RM70AG | \n", "RM70AG | \n", "1 | \n", "1 | \n", "1 | \n", "England | \n", "London SCN | \n", "Barking | \n", "Havering and Redbridge University Hospitals N... | \n", "Queens Hospital Romford HASU | \n", "... | \n", "11.9 | \n", "551118 | \n", "187780 | \n", "0.179030640661934 | \n", "51.5686465521504 | \n", "1 | \n", "0 | \n", "Romford | \n", "\n", " | POINT (19932.617 6722504.230) | \n", "
1 | \n", "E11BB | \n", "E11BB | \n", "1 | \n", "1 | \n", "1 | \n", "England | \n", "London SCN | \n", "Barts Health NHS Trust | \n", "The Royal London Hospital | \n", "Royal London Hospital HASU | \n", "... | \n", "13.4 | \n", "534829 | \n", "181798 | \n", "-0.0581329916047372 | \n", "51.5190178361295 | \n", "1 | \n", "1 | \n", "Royal London | \n", "\n", " | POINT (-6468.377 6713620.832) | \n", "
2 rows × 22 columns
\n", "\n", " | LSOA11CD | \n", "LSOA | \n", "LSOA11NMW | \n", "geometry | \n", "polygon_area_km2 | \n", "closest_ivt_unit | \n", "closest_mt_unit | \n", "closest_mt_transfer | \n", "la_district_name_2019 | \n", "rural_urban_2011 | \n", "... | \n", "lsoa_code | \n", "region | \n", "region_code | \n", "region_type | \n", "short_code | \n", "icb | \n", "icb_code | \n", "isdn | \n", "lhb | \n", "icb_lhb | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "E01000001 | \n", "City of London 001A | \n", "City of London 001A | \n", "POLYGON ((532105.092 182011.230, 532162.491 18... | \n", "0.343907 | \n", "E11BB | \n", "E11BB | \n", "E11BB | \n", "City of London | \n", "Urban major conurbation | \n", "... | \n", "E01000001 | \n", "NHS North East London ICB - A3A8R | \n", "E38000255 | \n", "SICBL | \n", "NEL | \n", "NHS North East London Integrated Care Board | \n", "E54000029 | \n", "London | \n", "NaN | \n", "NHS North East London Integrated Care Board | \n", "
1 | \n", "E01000002 | \n", "City of London 001B | \n", "City of London 001B | \n", "POLYGON ((532746.813 181786.891, 532671.688 18... | \n", "0.583474 | \n", "E11BB | \n", "E11BB | \n", "E11BB | \n", "City of London | \n", "Urban major conurbation | \n", "... | \n", "E01000002 | \n", "NHS North East London ICB - A3A8R | \n", "E38000255 | \n", "SICBL | \n", "NEL | \n", "NHS North East London Integrated Care Board | \n", "E54000029 | \n", "London | \n", "NaN | \n", "NHS North East London Integrated Care Board | \n", "
2 | \n", "E01000003 | \n", "City of London 001C | \n", "City of London 001C | \n", "POLYGON ((532135.145 182198.119, 532158.250 18... | \n", "0.147840 | \n", "E11BB | \n", "E11BB | \n", "E11BB | \n", "City of London | \n", "Urban major conurbation | \n", "... | \n", "E01000003 | \n", "NHS North East London ICB - A3A8R | \n", "E38000255 | \n", "SICBL | \n", "NEL | \n", "NHS North East London Integrated Care Board | \n", "E54000029 | \n", "London | \n", "NaN | \n", "NHS North East London Integrated Care Board | \n", "
3 | \n", "E01000005 | \n", "City of London 001E | \n", "City of London 001E | \n", "POLYGON ((533807.946 180767.770, 533649.063 18... | \n", "0.491918 | \n", "E11BB | \n", "E11BB | \n", "E11BB | \n", "City of London | \n", "Urban major conurbation | \n", "... | \n", "E01000005 | \n", "NHS North East London ICB - A3A8R | \n", "E38000255 | \n", "SICBL | \n", "NEL | \n", "NHS North East London Integrated Care Board | \n", "E54000029 | \n", "London | \n", "NaN | \n", "NHS North East London Integrated Care Board | \n", "
4 | \n", "E01000006 | \n", "Barking and Dagenham 016A | \n", "Barking and Dagenham 016A | \n", "POLYGON ((545122.049 184314.931, 545271.917 18... | \n", "0.372257 | \n", "RM70AG | \n", "RM70AG | \n", "RM70AG | \n", "Barking and Dagenham | \n", "Urban major conurbation | \n", "... | \n", "E01000006 | \n", "NHS North East London ICB - A3A8R | \n", "E38000255 | \n", "SICBL | \n", "NEL | \n", "NHS North East London Integrated Care Board | \n", "E54000029 | \n", "London | \n", "NaN | \n", "NHS North East London Integrated Care Board | \n", "
5 rows × 25 columns
\n", "