From 910a222fa60ce6ea0831f2956470b8a0b9f62670 Mon Sep 17 00:00:00 2001 From: leshe4ka46 Date: Sat, 18 Oct 2025 12:25:53 +0300 Subject: nvidia2 --- .../4-03_nearest_facilities.ipynb | 4102 ++++++++++++++++++++ 1 file changed, 4102 insertions(+) create mode 100644 Fundamentals_of_Accelerated_Data_Science/4-03_nearest_facilities.ipynb (limited to 'Fundamentals_of_Accelerated_Data_Science/4-03_nearest_facilities.ipynb') diff --git a/Fundamentals_of_Accelerated_Data_Science/4-03_nearest_facilities.ipynb b/Fundamentals_of_Accelerated_Data_Science/4-03_nearest_facilities.ipynb new file mode 100644 index 0000000..cc49bf1 --- /dev/null +++ b/Fundamentals_of_Accelerated_Data_Science/4-03_nearest_facilities.ipynb @@ -0,0 +1,4102 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"Header\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Week 2: Identify Nearest Health Facilities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "**UPDATE**\n", + "\n", + "Thank you for your analysis. Despite our warning efforts so far, the virus continues to spread rapidly. We want to get infected individuals treatment as quickly as possible, so we need your help to calculate which hospital or clinic is closest to each known infected individual in the population.\n", + "\n", + "\n", + "Your goal for this notebook will be to identify the nearest hospital or clinic for each infected person." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext cudf.pandas\n", + "import pandas as pd\n", + "import cuml\n", + "import cupy as cp" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Load Population Data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Begin by loading the `lat`, `long` and `infected` columns from `'./data/week2.csv'` into a cuDF-accelerated pandas DataFrame called `df`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
latlonginfected
054.522510-1.5718960.0
154.554030-1.5249680.0
254.552486-1.4352030.0
354.537189-1.5662150.0
454.528212-1.5884620.0
............
5847988951.634416-2.9258630.0
5847989051.556972-3.0362900.0
5847989151.588992-2.9219150.0
5847989251.590974-2.9545390.0
5847989351.576716-2.9521420.0
\n", + "

58479894 rows × 3 columns

\n", + "
" + ], + "text/plain": [ + " lat long infected\n", + "0 54.522510 -1.571896 0.0\n", + "1 54.554030 -1.524968 0.0\n", + "2 54.552486 -1.435203 0.0\n", + "3 54.537189 -1.566215 0.0\n", + "4 54.528212 -1.588462 0.0\n", + "... ... ... ...\n", + "58479889 51.634416 -2.925863 0.0\n", + "58479890 51.556972 -3.036290 0.0\n", + "58479891 51.588992 -2.921915 0.0\n", + "58479892 51.590974 -2.954539 0.0\n", + "58479893 51.576716 -2.952142 0.0\n", + "\n", + "[58479894 rows x 3 columns]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv('./data/week2.csv', usecols=['lat', 'long', 'infected'])\n", + "df" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Load Hospital and Clinics Data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For this step, your goal is to create an `all_med` cuDF-accelearted pandas DataFrame that contains the latitudes and longitudes of all the hospitals (data found at `'./data/hospitals.csv'`) and clinics (data found at `'./data/clinics.csv'`)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeSectorOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2...CountyPostcodeLatitudeLongitudeParentODSCodeParentNamePhoneEmailWebsiteFax
017970NDA07HospitalHospitalIndependent SectorVisibleTrueWalton Community Hospital - Virgin Care Servic...<NA>Rodney Road...SurreyKT12 3LD51.37999725-0.406042069NDAVirgin Care Services Ltd01932 414205<NA><NA>01932 253674
117981NDA18HospitalHospitalIndependent SectorVisibleTrueWoking Community Hospital (Virgin Care)<NA>Heathside Road...SurreyGU22 7HS51.31513214-0.556289494NDAVirgin Care Services Ltd01483 715911<NA><NA><NA>
218102NLT02HospitalHospitalNHS SectorVisibleTrueNorth Somerset Community HospitalNorth Somerset Community HospitalOld Street...AvonBS21 6BS51.43719482-2.847192764NLTNorth Somerset Community Partnership Community...01275 872212<NA>http://www.nscphealth.co.uk<NA>
318138NMP01HospitalHospitalIndependent SectorVisibleFalseBridgewater Hospital120 Princess Road<NA>...Greater ManchesterM15 5AT53.4597435-2.245468855NMPBridgewater Hospital (Manchester) Ltd0161 2270000<NA>www.bridgewaterhospital.com<NA>
418142NMV01HospitalHospitalIndependent SectorVisibleTrueKneesworth HouseOld North RoadBassingbourn...<NA>SG8 5JP52.07812119-0.030604055NMVPartnerships In Care Ltd01763 255 700reception_kneesworthhouse@partnershipsincare.c...www.partnershipsincare.co.uk<NA>
..................................................................
122410617466RTH18HospitalUNKNOWNIndependent SectorVisibleFalseUniversity Hospital Of WalesC/O John Radcliffe HospitalHeadley Way...<NA>OX3 9DU51.76387405-1.219792008RTHOxford University Hospitals NHS Foundation Trust<NA><NA><NA><NA>
122510617482RX3KIHospitalUNKNOWNIndependent SectorVisibleFalseFoss Park HospitalHuntington HouseJockey Lane...<NA>YO32 9XW53.98666382-1.051122308RX3Tees, Esk and Wear Valleys NHS Foundation Trust<NA><NA><NA><NA>
122610617567RGT1WHospitalUNKNOWNIndependent SectorVisibleFalseJersey General HospitalThe Parade<NA>...<NA>JE1 3UH<NA><NA>RGTCambridge University Hospitals NHS Foundation ...<NA><NA><NA><NA>
122710617714RAX0AHospitalUNKNOWNIndependent SectorVisibleFalseLondon North West University HospitalsWatford Road<NA>...<NA>HA1 3UJ51.57540894-0.322022736RAXKingston Hospital NHS Foundation Trust<NA><NA><NA><NA>
122810617726RDU5AHospitalUNKNOWNIndependent SectorVisibleFalseJohn Radcliffe HospitalHeadley WayHeadington...<NA>OX3 9DU51.76387405-1.219792008RDUFrimley Health NHS Foundation Trust<NA><NA><NA><NA>
\n", + "

1229 rows × 22 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType \\\n", + "0 17970 NDA07 Hospital Hospital \n", + "1 17981 NDA18 Hospital Hospital \n", + "2 18102 NLT02 Hospital Hospital \n", + "3 18138 NMP01 Hospital Hospital \n", + "4 18142 NMV01 Hospital Hospital \n", + "... ... ... ... ... \n", + "1224 10617466 RTH18 Hospital UNKNOWN \n", + "1225 10617482 RX3KI Hospital UNKNOWN \n", + "1226 10617567 RGT1W Hospital UNKNOWN \n", + "1227 10617714 RAX0A Hospital UNKNOWN \n", + "1228 10617726 RDU5A Hospital UNKNOWN \n", + "\n", + " Sector OrganisationStatus IsPimsManaged \\\n", + "0 Independent Sector Visible True \n", + "1 Independent Sector Visible True \n", + "2 NHS Sector Visible True \n", + "3 Independent Sector Visible False \n", + "4 Independent Sector Visible True \n", + "... ... ... ... \n", + "1224 Independent Sector Visible False \n", + "1225 Independent Sector Visible False \n", + "1226 Independent Sector Visible False \n", + "1227 Independent Sector Visible False \n", + "1228 Independent Sector Visible False \n", + "\n", + " OrganisationName \\\n", + "0 Walton Community Hospital - Virgin Care Servic... \n", + "1 Woking Community Hospital (Virgin Care) \n", + "2 North Somerset Community Hospital \n", + "3 Bridgewater Hospital \n", + "4 Kneesworth House \n", + "... ... \n", + "1224 University Hospital Of Wales \n", + "1225 Foss Park Hospital \n", + "1226 Jersey General Hospital \n", + "1227 London North West University Hospitals \n", + "1228 John Radcliffe Hospital \n", + "\n", + " Address1 Address2 ... \\\n", + "0 Rodney Road ... \n", + "1 Heathside Road ... \n", + "2 North Somerset Community Hospital Old Street ... \n", + "3 120 Princess Road ... \n", + "4 Old North Road Bassingbourn ... \n", + "... ... ... ... \n", + "1224 C/O John Radcliffe Hospital Headley Way ... \n", + "1225 Huntington House Jockey Lane ... \n", + "1226 The Parade ... \n", + "1227 Watford Road ... \n", + "1228 Headley Way Headington ... \n", + "\n", + " County Postcode Latitude Longitude ParentODSCode \\\n", + "0 Surrey KT12 3LD 51.37999725 -0.406042069 NDA \n", + "1 Surrey GU22 7HS 51.31513214 -0.556289494 NDA \n", + "2 Avon BS21 6BS 51.43719482 -2.847192764 NLT \n", + "3 Greater Manchester M15 5AT 53.4597435 -2.245468855 NMP \n", + "4 SG8 5JP 52.07812119 -0.030604055 NMV \n", + "... ... ... ... ... ... \n", + "1224 OX3 9DU 51.76387405 -1.219792008 RTH \n", + "1225 YO32 9XW 53.98666382 -1.051122308 RX3 \n", + "1226 JE1 3UH RGT \n", + "1227 HA1 3UJ 51.57540894 -0.322022736 RAX \n", + "1228 OX3 9DU 51.76387405 -1.219792008 RDU \n", + "\n", + " ParentName Phone \\\n", + "0 Virgin Care Services Ltd 01932 414205 \n", + "1 Virgin Care Services Ltd 01483 715911 \n", + "2 North Somerset Community Partnership Community... 01275 872212 \n", + "3 Bridgewater Hospital (Manchester) Ltd 0161 2270000 \n", + "4 Partnerships In Care Ltd 01763 255 700 \n", + "... ... ... \n", + "1224 Oxford University Hospitals NHS Foundation Trust \n", + "1225 Tees, Esk and Wear Valleys NHS Foundation Trust \n", + "1226 Cambridge University Hospitals NHS Foundation ... \n", + "1227 Kingston Hospital NHS Foundation Trust \n", + "1228 Frimley Health NHS Foundation Trust \n", + "\n", + " Email \\\n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 reception_kneesworthhouse@partnershipsincare.c... \n", + "... ... \n", + "1224 \n", + "1225 \n", + "1226 \n", + "1227 \n", + "1228 \n", + "\n", + " Website Fax \n", + "0 01932 253674 \n", + "1 \n", + "2 http://www.nscphealth.co.uk \n", + "3 www.bridgewaterhospital.com \n", + "4 www.partnershipsincare.co.uk \n", + "... ... ... \n", + "1224 \n", + "1225 \n", + "1226 \n", + "1227 \n", + "1228 \n", + "\n", + "[1229 rows x 22 columns]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "hospitals_df = pd.read_csv('./data/hospitals.csv')\n", + "hospitals_df" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2Address3CityCountyPostcodeLatitudeLongitudePhoneEmailWebsiteFax
012366F81157ClinicUNKNOWNVisibleTrueFrinton Road Medical Centre<NA>68 Frinton Road, Hollond-on-Sea<NA>Clacton-on-Sea<NA>CO15 5UW51.8042371.186376<NA><NA><NA><NA>
112450F81670ClinicUNKNOWNVisibleTrueEpping Close Surgery<NA>Epping Close<NA>Clacton on Sea<NA>CO15 4UZ51.8152621.15470701255 222668<NA><NA><NA>
212461F81681ClinicUNKNOWNVisibleTrueGreen Elms Medical Centre<NA>32 Crossways<NA>Jaywick, Clacton on Sea<NA>CO15 2NB51.7806211.117907<NA><NA><NA><NA>
317937NAA01ClinicUNKNOWNVisibleFalseSt Chads ClinicSt. Chads Drive<NA><NA>LiverpoolMerseysideL32 8RE53.482368-2.885404<NA><NA><NA><NA>
417938NAA02ClinicUNKNOWNVisibleFalseWhiston Health CentreOld Colliery RoadWhiston<NA>PrescotMerseysideL35 3SX53.415630-2.800874<NA><NA><NA><NA>
............................................................
1907710617742NBG7LClinicUNKNOWNVisibleFalseSunnybank Medical CentreTown GateWyke<NA>Bradford<NA>BD12 9NG53.737923-1.767982<NA><NA><NA><NA>
1907810617743NFH02ClinicUNKNOWNVisibleFalseSomerset Surgical Services At Mendip Vale Medi...Pudding Pie LaneLangford<NA>Bristol<NA>BS40 5EL51.341579-2.784808<NA><NA><NA><NA>
1907910617744NFH03ClinicUNKNOWNVisibleFalseSomerset Surgical Services At Axbridge Medical...Houlgate Way<NA><NA>Axbridge<NA>BS26 2BJ51.286285-2.820388<NA><NA><NA><NA>
1908010617746NEMAMClinicUNKNOWNVisibleFalseLawton House SurgeryBromley Road<NA><NA>Congleton<NA>CW12 1QG53.163048-2.205781<NA><NA><NA><NA>
1908110617747NFH04ClinicUNKNOWNVisibleFalseSomerset Surgical Services At Wedmore Medical ...St. Medard Road<NA><NA>Wedmore<NA>BS28 4AY51.227219-2.816258<NA><NA><NA><NA>
\n", + "

19082 rows × 19 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType \\\n", + "0 12366 F81157 Clinic UNKNOWN \n", + "1 12450 F81670 Clinic UNKNOWN \n", + "2 12461 F81681 Clinic UNKNOWN \n", + "3 17937 NAA01 Clinic UNKNOWN \n", + "4 17938 NAA02 Clinic UNKNOWN \n", + "... ... ... ... ... \n", + "19077 10617742 NBG7L Clinic UNKNOWN \n", + "19078 10617743 NFH02 Clinic UNKNOWN \n", + "19079 10617744 NFH03 Clinic UNKNOWN \n", + "19080 10617746 NEMAM Clinic UNKNOWN \n", + "19081 10617747 NFH04 Clinic UNKNOWN \n", + "\n", + " OrganisationStatus IsPimsManaged \\\n", + "0 Visible True \n", + "1 Visible True \n", + "2 Visible True \n", + "3 Visible False \n", + "4 Visible False \n", + "... ... ... \n", + "19077 Visible False \n", + "19078 Visible False \n", + "19079 Visible False \n", + "19080 Visible False \n", + "19081 Visible False \n", + "\n", + " OrganisationName Address1 \\\n", + "0 Frinton Road Medical Centre \n", + "1 Epping Close Surgery \n", + "2 Green Elms Medical Centre \n", + "3 St Chads Clinic St. Chads Drive \n", + "4 Whiston Health Centre Old Colliery Road \n", + "... ... ... \n", + "19077 Sunnybank Medical Centre Town Gate \n", + "19078 Somerset Surgical Services At Mendip Vale Medi... Pudding Pie Lane \n", + "19079 Somerset Surgical Services At Axbridge Medical... Houlgate Way \n", + "19080 Lawton House Surgery Bromley Road \n", + "19081 Somerset Surgical Services At Wedmore Medical ... St. Medard Road \n", + "\n", + " Address2 Address3 City \\\n", + "0 68 Frinton Road, Hollond-on-Sea Clacton-on-Sea \n", + "1 Epping Close Clacton on Sea \n", + "2 32 Crossways Jaywick, Clacton on Sea \n", + "3 Liverpool \n", + "4 Whiston Prescot \n", + "... ... ... ... \n", + "19077 Wyke Bradford \n", + "19078 Langford Bristol \n", + "19079 Axbridge \n", + "19080 Congleton \n", + "19081 Wedmore \n", + "\n", + " County Postcode Latitude Longitude Phone Email Website \\\n", + "0 CO15 5UW 51.804237 1.186376 \n", + "1 CO15 4UZ 51.815262 1.154707 01255 222668 \n", + "2 CO15 2NB 51.780621 1.117907 \n", + "3 Merseyside L32 8RE 53.482368 -2.885404 \n", + "4 Merseyside L35 3SX 53.415630 -2.800874 \n", + "... ... ... ... ... ... ... ... \n", + "19077 BD12 9NG 53.737923 -1.767982 \n", + "19078 BS40 5EL 51.341579 -2.784808 \n", + "19079 BS26 2BJ 51.286285 -2.820388 \n", + "19080 CW12 1QG 53.163048 -2.205781 \n", + "19081 BS28 4AY 51.227219 -2.816258 \n", + "\n", + " Fax \n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 \n", + "... ... \n", + "19077 \n", + "19078 \n", + "19079 \n", + "19080 \n", + "19081 \n", + "\n", + "[19082 rows x 19 columns]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "clinics_df = pd.read_csv('./data/clinics.csv')\n", + "clinics_df" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeSectorOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2...CountyPostcodeLatitudeLongitudeParentODSCodeParentNamePhoneEmailWebsiteFax
017970NDA07HospitalHospitalIndependent SectorVisibleTrueWalton Community Hospital - Virgin Care Servic...<NA>Rodney Road...SurreyKT12 3LD51.379997-0.406042NDAVirgin Care Services Ltd01932 414205<NA><NA>01932 253674
117981NDA18HospitalHospitalIndependent SectorVisibleTrueWoking Community Hospital (Virgin Care)<NA>Heathside Road...SurreyGU22 7HS51.315132-0.556289NDAVirgin Care Services Ltd01483 715911<NA><NA><NA>
218102NLT02HospitalHospitalNHS SectorVisibleTrueNorth Somerset Community HospitalNorth Somerset Community HospitalOld Street...AvonBS21 6BS51.437195-2.847193NLTNorth Somerset Community Partnership Community...01275 872212<NA>http://www.nscphealth.co.uk<NA>
318138NMP01HospitalHospitalIndependent SectorVisibleFalseBridgewater Hospital120 Princess Road<NA>...Greater ManchesterM15 5AT53.459743-2.245469NMPBridgewater Hospital (Manchester) Ltd0161 2270000<NA>www.bridgewaterhospital.com<NA>
418142NMV01HospitalHospitalIndependent SectorVisibleTrueKneesworth HouseOld North RoadBassingbourn...<NA>SG8 5JP52.078121-0.030604NMVPartnerships In Care Ltd01763 255 700reception_kneesworthhouse@partnershipsincare.c...www.partnershipsincare.co.uk<NA>
..................................................................
1907710617742NBG7LClinicUNKNOWN<NA>VisibleFalseSunnybank Medical CentreTown GateWyke...<NA>BD12 9NG53.737923-1.767982<NA><NA><NA><NA><NA><NA>
1907810617743NFH02ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Mendip Vale Medi...Pudding Pie LaneLangford...<NA>BS40 5EL51.341579-2.784808<NA><NA><NA><NA><NA><NA>
1907910617744NFH03ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Axbridge Medical...Houlgate Way<NA>...<NA>BS26 2BJ51.286285-2.820388<NA><NA><NA><NA><NA><NA>
1908010617746NEMAMClinicUNKNOWN<NA>VisibleFalseLawton House SurgeryBromley Road<NA>...<NA>CW12 1QG53.163048-2.205781<NA><NA><NA><NA><NA><NA>
1908110617747NFH04ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Wedmore Medical ...St. Medard Road<NA>...<NA>BS28 4AY51.227219-2.816258<NA><NA><NA><NA><NA><NA>
\n", + "

20311 rows × 22 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType \\\n", + "0 17970 NDA07 Hospital Hospital \n", + "1 17981 NDA18 Hospital Hospital \n", + "2 18102 NLT02 Hospital Hospital \n", + "3 18138 NMP01 Hospital Hospital \n", + "4 18142 NMV01 Hospital Hospital \n", + "... ... ... ... ... \n", + "19077 10617742 NBG7L Clinic UNKNOWN \n", + "19078 10617743 NFH02 Clinic UNKNOWN \n", + "19079 10617744 NFH03 Clinic UNKNOWN \n", + "19080 10617746 NEMAM Clinic UNKNOWN \n", + "19081 10617747 NFH04 Clinic UNKNOWN \n", + "\n", + " Sector OrganisationStatus IsPimsManaged \\\n", + "0 Independent Sector Visible True \n", + "1 Independent Sector Visible True \n", + "2 NHS Sector Visible True \n", + "3 Independent Sector Visible False \n", + "4 Independent Sector Visible True \n", + "... ... ... ... \n", + "19077 Visible False \n", + "19078 Visible False \n", + "19079 Visible False \n", + "19080 Visible False \n", + "19081 Visible False \n", + "\n", + " OrganisationName \\\n", + "0 Walton Community Hospital - Virgin Care Servic... \n", + "1 Woking Community Hospital (Virgin Care) \n", + "2 North Somerset Community Hospital \n", + "3 Bridgewater Hospital \n", + "4 Kneesworth House \n", + "... ... \n", + "19077 Sunnybank Medical Centre \n", + "19078 Somerset Surgical Services At Mendip Vale Medi... \n", + "19079 Somerset Surgical Services At Axbridge Medical... \n", + "19080 Lawton House Surgery \n", + "19081 Somerset Surgical Services At Wedmore Medical ... \n", + "\n", + " Address1 Address2 ... \\\n", + "0 Rodney Road ... \n", + "1 Heathside Road ... \n", + "2 North Somerset Community Hospital Old Street ... \n", + "3 120 Princess Road ... \n", + "4 Old North Road Bassingbourn ... \n", + "... ... ... ... \n", + "19077 Town Gate Wyke ... \n", + "19078 Pudding Pie Lane Langford ... \n", + "19079 Houlgate Way ... \n", + "19080 Bromley Road ... \n", + "19081 St. Medard Road ... \n", + "\n", + " County Postcode Latitude Longitude ParentODSCode \\\n", + "0 Surrey KT12 3LD 51.379997 -0.406042 NDA \n", + "1 Surrey GU22 7HS 51.315132 -0.556289 NDA \n", + "2 Avon BS21 6BS 51.437195 -2.847193 NLT \n", + "3 Greater Manchester M15 5AT 53.459743 -2.245469 NMP \n", + "4 SG8 5JP 52.078121 -0.030604 NMV \n", + "... ... ... ... ... ... \n", + "19077 BD12 9NG 53.737923 -1.767982 \n", + "19078 BS40 5EL 51.341579 -2.784808 \n", + "19079 BS26 2BJ 51.286285 -2.820388 \n", + "19080 CW12 1QG 53.163048 -2.205781 \n", + "19081 BS28 4AY 51.227219 -2.816258 \n", + "\n", + " ParentName Phone \\\n", + "0 Virgin Care Services Ltd 01932 414205 \n", + "1 Virgin Care Services Ltd 01483 715911 \n", + "2 North Somerset Community Partnership Community... 01275 872212 \n", + "3 Bridgewater Hospital (Manchester) Ltd 0161 2270000 \n", + "4 Partnerships In Care Ltd 01763 255 700 \n", + "... ... ... \n", + "19077 \n", + "19078 \n", + "19079 \n", + "19080 \n", + "19081 \n", + "\n", + " Email \\\n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 reception_kneesworthhouse@partnershipsincare.c... \n", + "... ... \n", + "19077 \n", + "19078 \n", + "19079 \n", + "19080 \n", + "19081 \n", + "\n", + " Website Fax \n", + "0 01932 253674 \n", + "1 \n", + "2 http://www.nscphealth.co.uk \n", + "3 www.bridgewaterhospital.com \n", + "4 www.partnershipsincare.co.uk \n", + "... ... ... \n", + "19077 \n", + "19078 \n", + "19079 \n", + "19080 \n", + "19081 \n", + "\n", + "[20311 rows x 22 columns]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_med = pd.concat([hospitals_df, clinics_df])\n", + "all_med" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since we will be using the coordinates of those facilities, keep only those rows that are non-null in both `Latitude` and `Longitude`.\n", + "\n", + "**Tip**: Reset the index of `all_med` with `.reset_index(drop=True)`. " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeSectorOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2...CountyPostcodeLatitudeLongitudeParentODSCodeParentNamePhoneEmailWebsiteFax
017970NDA07HospitalHospitalIndependent SectorVisibleTrueWalton Community Hospital - Virgin Care Servic...<NA>Rodney Road...SurreyKT12 3LD51.379997-0.406042NDAVirgin Care Services Ltd01932 414205<NA><NA>01932 253674
117981NDA18HospitalHospitalIndependent SectorVisibleTrueWoking Community Hospital (Virgin Care)<NA>Heathside Road...SurreyGU22 7HS51.315132-0.556289NDAVirgin Care Services Ltd01483 715911<NA><NA><NA>
218102NLT02HospitalHospitalNHS SectorVisibleTrueNorth Somerset Community HospitalNorth Somerset Community HospitalOld Street...AvonBS21 6BS51.437195-2.847193NLTNorth Somerset Community Partnership Community...01275 872212<NA>http://www.nscphealth.co.uk<NA>
318138NMP01HospitalHospitalIndependent SectorVisibleFalseBridgewater Hospital120 Princess Road<NA>...Greater ManchesterM15 5AT53.459743-2.245469NMPBridgewater Hospital (Manchester) Ltd0161 2270000<NA>www.bridgewaterhospital.com<NA>
418142NMV01HospitalHospitalIndependent SectorVisibleTrueKneesworth HouseOld North RoadBassingbourn...<NA>SG8 5JP52.078121-0.030604NMVPartnerships In Care Ltd01763 255 700reception_kneesworthhouse@partnershipsincare.c...www.partnershipsincare.co.uk<NA>
..................................................................
2029610617742NBG7LClinicUNKNOWN<NA>VisibleFalseSunnybank Medical CentreTown GateWyke...<NA>BD12 9NG53.737923-1.767982<NA><NA><NA><NA><NA><NA>
2029710617743NFH02ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Mendip Vale Medi...Pudding Pie LaneLangford...<NA>BS40 5EL51.341579-2.784808<NA><NA><NA><NA><NA><NA>
2029810617744NFH03ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Axbridge Medical...Houlgate Way<NA>...<NA>BS26 2BJ51.286285-2.820388<NA><NA><NA><NA><NA><NA>
2029910617746NEMAMClinicUNKNOWN<NA>VisibleFalseLawton House SurgeryBromley Road<NA>...<NA>CW12 1QG53.163048-2.205781<NA><NA><NA><NA><NA><NA>
2030010617747NFH04ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Wedmore Medical ...St. Medard Road<NA>...<NA>BS28 4AY51.227219-2.816258<NA><NA><NA><NA><NA><NA>
\n", + "

20301 rows × 22 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType \\\n", + "0 17970 NDA07 Hospital Hospital \n", + "1 17981 NDA18 Hospital Hospital \n", + "2 18102 NLT02 Hospital Hospital \n", + "3 18138 NMP01 Hospital Hospital \n", + "4 18142 NMV01 Hospital Hospital \n", + "... ... ... ... ... \n", + "20296 10617742 NBG7L Clinic UNKNOWN \n", + "20297 10617743 NFH02 Clinic UNKNOWN \n", + "20298 10617744 NFH03 Clinic UNKNOWN \n", + "20299 10617746 NEMAM Clinic UNKNOWN \n", + "20300 10617747 NFH04 Clinic UNKNOWN \n", + "\n", + " Sector OrganisationStatus IsPimsManaged \\\n", + "0 Independent Sector Visible True \n", + "1 Independent Sector Visible True \n", + "2 NHS Sector Visible True \n", + "3 Independent Sector Visible False \n", + "4 Independent Sector Visible True \n", + "... ... ... ... \n", + "20296 Visible False \n", + "20297 Visible False \n", + "20298 Visible False \n", + "20299 Visible False \n", + "20300 Visible False \n", + "\n", + " OrganisationName \\\n", + "0 Walton Community Hospital - Virgin Care Servic... \n", + "1 Woking Community Hospital (Virgin Care) \n", + "2 North Somerset Community Hospital \n", + "3 Bridgewater Hospital \n", + "4 Kneesworth House \n", + "... ... \n", + "20296 Sunnybank Medical Centre \n", + "20297 Somerset Surgical Services At Mendip Vale Medi... \n", + "20298 Somerset Surgical Services At Axbridge Medical... \n", + "20299 Lawton House Surgery \n", + "20300 Somerset Surgical Services At Wedmore Medical ... \n", + "\n", + " Address1 Address2 ... \\\n", + "0 Rodney Road ... \n", + "1 Heathside Road ... \n", + "2 North Somerset Community Hospital Old Street ... \n", + "3 120 Princess Road ... \n", + "4 Old North Road Bassingbourn ... \n", + "... ... ... ... \n", + "20296 Town Gate Wyke ... \n", + "20297 Pudding Pie Lane Langford ... \n", + "20298 Houlgate Way ... \n", + "20299 Bromley Road ... \n", + "20300 St. Medard Road ... \n", + "\n", + " County Postcode Latitude Longitude ParentODSCode \\\n", + "0 Surrey KT12 3LD 51.379997 -0.406042 NDA \n", + "1 Surrey GU22 7HS 51.315132 -0.556289 NDA \n", + "2 Avon BS21 6BS 51.437195 -2.847193 NLT \n", + "3 Greater Manchester M15 5AT 53.459743 -2.245469 NMP \n", + "4 SG8 5JP 52.078121 -0.030604 NMV \n", + "... ... ... ... ... ... \n", + "20296 BD12 9NG 53.737923 -1.767982 \n", + "20297 BS40 5EL 51.341579 -2.784808 \n", + "20298 BS26 2BJ 51.286285 -2.820388 \n", + "20299 CW12 1QG 53.163048 -2.205781 \n", + "20300 BS28 4AY 51.227219 -2.816258 \n", + "\n", + " ParentName Phone \\\n", + "0 Virgin Care Services Ltd 01932 414205 \n", + "1 Virgin Care Services Ltd 01483 715911 \n", + "2 North Somerset Community Partnership Community... 01275 872212 \n", + "3 Bridgewater Hospital (Manchester) Ltd 0161 2270000 \n", + "4 Partnerships In Care Ltd 01763 255 700 \n", + "... ... ... \n", + "20296 \n", + "20297 \n", + "20298 \n", + "20299 \n", + "20300 \n", + "\n", + " Email \\\n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 reception_kneesworthhouse@partnershipsincare.c... \n", + "... ... \n", + "20296 \n", + "20297 \n", + "20298 \n", + "20299 \n", + "20300 \n", + "\n", + " Website Fax \n", + "0 01932 253674 \n", + "1 \n", + "2 http://www.nscphealth.co.uk \n", + "3 www.bridgewaterhospital.com \n", + "4 www.partnershipsincare.co.uk \n", + "... ... ... \n", + "20296 \n", + "20297 \n", + "20298 \n", + "20299 \n", + "20300 \n", + "\n", + "[20301 rows x 22 columns]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_med = all_med.dropna(subset=['Latitude', 'Longitude'])\n", + "\n", + "all_med = all_med.reset_index(drop=True)\n", + "\n", + "all_med " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Make Grid Coordinates for Medical Facilities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Provided for you in the next cell (which you can expand by clicking on the \"...\", and contract again after executing by clicking on the blue left border of the cell) is the lat/long to grid coordinates converter you have used earlier in the workshop. Use this converter to create grid coordinate values stored in `northing` and `easting` columns of the `all_med` DataFrame you created in the last step." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# https://www.ordnancesurvey.co.uk/docs/support/guide-coordinate-systems-great-britain.pdf\n", + "\n", + "def latlong2osgbgrid_cupy(lat, long, input_degrees=True):\n", + " '''\n", + " Converts latitude and longitude (ellipsoidal) coordinates into northing and easting (grid) coordinates, using a Transverse Mercator projection.\n", + " \n", + " Inputs:\n", + " lat: latitude coordinate (N)\n", + " long: longitude coordinate (E)\n", + " input_degrees: if True (default), interprets the coordinates as degrees; otherwise, interprets coordinates as radians\n", + " \n", + " Output:\n", + " (northing, easting)\n", + " '''\n", + " \n", + " if input_degrees:\n", + " lat = lat * cp.pi/180\n", + " long = long * cp.pi/180\n", + "\n", + " a = 6377563.396\n", + " b = 6356256.909\n", + " e2 = (a**2 - b**2) / a**2\n", + "\n", + " N0 = -100000 # northing of true origin\n", + " E0 = 400000 # easting of true origin\n", + " F0 = .9996012717 # scale factor on central meridian\n", + " phi0 = 49 * cp.pi / 180 # latitude of true origin\n", + " lambda0 = -2 * cp.pi / 180 # longitude of true origin and central meridian\n", + " \n", + " sinlat = cp.sin(lat)\n", + " coslat = cp.cos(lat)\n", + " tanlat = cp.tan(lat)\n", + " \n", + " latdiff = lat-phi0\n", + " longdiff = long-lambda0\n", + "\n", + " n = (a-b) / (a+b)\n", + " nu = a * F0 * (1 - e2 * sinlat ** 2) ** -.5\n", + " rho = a * F0 * (1 - e2) * (1 - e2 * sinlat ** 2) ** -1.5\n", + " eta2 = nu / rho - 1\n", + " M = b * F0 * ((1 + n + 5/4 * (n**2 + n**3)) * latdiff - \n", + " (3*(n+n**2) + 21/8 * n**3) * cp.sin(latdiff) * cp.cos(lat+phi0) +\n", + " 15/8 * (n**2 + n**3) * cp.sin(2*(latdiff)) * cp.cos(2*(lat+phi0)) - \n", + " 35/24 * n**3 * cp.sin(3*(latdiff)) * cp.cos(3*(lat+phi0)))\n", + " I = M + N0\n", + " II = nu/2 * sinlat * coslat\n", + " III = nu/24 * sinlat * coslat ** 3 * (5 - tanlat ** 2 + 9 * eta2)\n", + " IIIA = nu/720 * sinlat * coslat ** 5 * (61-58 * tanlat**2 + tanlat**4)\n", + " IV = nu * coslat\n", + " V = nu / 6 * coslat**3 * (nu/rho - cp.tan(lat)**2)\n", + " VI = nu / 120 * coslat ** 5 * (5 - 18 * tanlat**2 + tanlat**4 + 14 * eta2 - 58 * tanlat**2 * eta2)\n", + "\n", + " northing = I + II * longdiff**2 + III * longdiff**4 + IIIA * longdiff**6\n", + " easting = E0 + IV * longdiff + V * longdiff**3 + VI * longdiff**5\n", + "\n", + " return(northing, easting)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeSectorOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2...LatitudeLongitudeParentODSCodeParentNamePhoneEmailWebsiteFaxnorthingeasting
017970NDA07HospitalHospitalIndependent SectorVisibleTrueWalton Community Hospital - Virgin Care Servic...<NA>Rodney Road...51.379997-0.406042NDAVirgin Care Services Ltd01932 414205<NA><NA>01932 253674165810.473974510917.517174
117981NDA18HospitalHospitalIndependent SectorVisibleTrueWoking Community Hospital (Virgin Care)<NA>Heathside Road...51.315132-0.556289NDAVirgin Care Services Ltd01483 715911<NA><NA><NA>158381.343420500604.836652
218102NLT02HospitalHospitalNHS SectorVisibleTrueNorth Somerset Community HospitalNorth Somerset Community HospitalOld Street...51.437195-2.847193NLTNorth Somerset Community Partnership Community...01275 872212<NA>http://www.nscphealth.co.uk<NA>171305.775859341119.365090
318138NMP01HospitalHospitalIndependent SectorVisibleFalseBridgewater Hospital120 Princess Road<NA>...53.459743-2.245469NMPBridgewater Hospital (Manchester) Ltd0161 2270000<NA>www.bridgewaterhospital.com<NA>395944.561405383703.600293
418142NMV01HospitalHospitalIndependent SectorVisibleTrueKneesworth HouseOld North RoadBassingbourn...52.078121-0.030604NMVPartnerships In Care Ltd01763 255 700reception_kneesworthhouse@partnershipsincare.c...www.partnershipsincare.co.uk<NA>244071.710013534945.182860
..................................................................
2029610617742NBG7LClinicUNKNOWN<NA>VisibleFalseSunnybank Medical CentreTown GateWyke...53.737923-1.767982<NA><NA><NA><NA><NA><NA>426887.040596415302.519662
2029710617743NFH02ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Mendip Vale Medi...Pudding Pie LaneLangford...51.341579-2.784808<NA><NA><NA><NA><NA><NA>160625.127012345341.262026
2029810617744NFH03ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Axbridge Medical...Houlgate Way<NA>...51.286285-2.820388<NA><NA><NA><NA><NA><NA>154503.665383342794.591249
2029910617746NEMAMClinicUNKNOWN<NA>VisibleFalseLawton House SurgeryBromley Road<NA>...53.163048-2.205781<NA><NA><NA><NA><NA><NA>362932.494686386243.408863
2030010617747NFH04ClinicUNKNOWN<NA>VisibleFalseSomerset Surgical Services At Wedmore Medical ...St. Medard Road<NA>...51.227219-2.816258<NA><NA><NA><NA><NA><NA>147932.429756343009.593212
\n", + "

20301 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType \\\n", + "0 17970 NDA07 Hospital Hospital \n", + "1 17981 NDA18 Hospital Hospital \n", + "2 18102 NLT02 Hospital Hospital \n", + "3 18138 NMP01 Hospital Hospital \n", + "4 18142 NMV01 Hospital Hospital \n", + "... ... ... ... ... \n", + "20296 10617742 NBG7L Clinic UNKNOWN \n", + "20297 10617743 NFH02 Clinic UNKNOWN \n", + "20298 10617744 NFH03 Clinic UNKNOWN \n", + "20299 10617746 NEMAM Clinic UNKNOWN \n", + "20300 10617747 NFH04 Clinic UNKNOWN \n", + "\n", + " Sector OrganisationStatus IsPimsManaged \\\n", + "0 Independent Sector Visible True \n", + "1 Independent Sector Visible True \n", + "2 NHS Sector Visible True \n", + "3 Independent Sector Visible False \n", + "4 Independent Sector Visible True \n", + "... ... ... ... \n", + "20296 Visible False \n", + "20297 Visible False \n", + "20298 Visible False \n", + "20299 Visible False \n", + "20300 Visible False \n", + "\n", + " OrganisationName \\\n", + "0 Walton Community Hospital - Virgin Care Servic... \n", + "1 Woking Community Hospital (Virgin Care) \n", + "2 North Somerset Community Hospital \n", + "3 Bridgewater Hospital \n", + "4 Kneesworth House \n", + "... ... \n", + "20296 Sunnybank Medical Centre \n", + "20297 Somerset Surgical Services At Mendip Vale Medi... \n", + "20298 Somerset Surgical Services At Axbridge Medical... \n", + "20299 Lawton House Surgery \n", + "20300 Somerset Surgical Services At Wedmore Medical ... \n", + "\n", + " Address1 Address2 ... Latitude \\\n", + "0 Rodney Road ... 51.379997 \n", + "1 Heathside Road ... 51.315132 \n", + "2 North Somerset Community Hospital Old Street ... 51.437195 \n", + "3 120 Princess Road ... 53.459743 \n", + "4 Old North Road Bassingbourn ... 52.078121 \n", + "... ... ... ... ... \n", + "20296 Town Gate Wyke ... 53.737923 \n", + "20297 Pudding Pie Lane Langford ... 51.341579 \n", + "20298 Houlgate Way ... 51.286285 \n", + "20299 Bromley Road ... 53.163048 \n", + "20300 St. Medard Road ... 51.227219 \n", + "\n", + " Longitude ParentODSCode \\\n", + "0 -0.406042 NDA \n", + "1 -0.556289 NDA \n", + "2 -2.847193 NLT \n", + "3 -2.245469 NMP \n", + "4 -0.030604 NMV \n", + "... ... ... \n", + "20296 -1.767982 \n", + "20297 -2.784808 \n", + "20298 -2.820388 \n", + "20299 -2.205781 \n", + "20300 -2.816258 \n", + "\n", + " ParentName Phone \\\n", + "0 Virgin Care Services Ltd 01932 414205 \n", + "1 Virgin Care Services Ltd 01483 715911 \n", + "2 North Somerset Community Partnership Community... 01275 872212 \n", + "3 Bridgewater Hospital (Manchester) Ltd 0161 2270000 \n", + "4 Partnerships In Care Ltd 01763 255 700 \n", + "... ... ... \n", + "20296 \n", + "20297 \n", + "20298 \n", + "20299 \n", + "20300 \n", + "\n", + " Email \\\n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 reception_kneesworthhouse@partnershipsincare.c... \n", + "... ... \n", + "20296 \n", + "20297 \n", + "20298 \n", + "20299 \n", + "20300 \n", + "\n", + " Website Fax northing \\\n", + "0 01932 253674 165810.473974 \n", + "1 158381.343420 \n", + "2 http://www.nscphealth.co.uk 171305.775859 \n", + "3 www.bridgewaterhospital.com 395944.561405 \n", + "4 www.partnershipsincare.co.uk 244071.710013 \n", + "... ... ... ... \n", + "20296 426887.040596 \n", + "20297 160625.127012 \n", + "20298 154503.665383 \n", + "20299 362932.494686 \n", + "20300 147932.429756 \n", + "\n", + " easting \n", + "0 510917.517174 \n", + "1 500604.836652 \n", + "2 341119.365090 \n", + "3 383703.600293 \n", + "4 534945.182860 \n", + "... ... \n", + "20296 415302.519662 \n", + "20297 345341.262026 \n", + "20298 342794.591249 \n", + "20299 386243.408863 \n", + "20300 343009.593212 \n", + "\n", + "[20301 rows x 24 columns]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cupy_lat = cp.asarray(all_med['Latitude'])\n", + "cupy_long = cp.asarray(all_med['Longitude'])\n", + "\n", + "all_med['northing'], all_med['easting'] = latlong2osgbgrid_cupy(cupy_lat, cupy_long)\n", + "all_med" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Find Closest Hospital or Clinic for Infected" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Fit `cuml.NearestNeighbors` with `all_med`'s `northing` and `easting` values, using the named argument `n_neighbors` set to `1`, and save the model as `knn`." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
NearestNeighbors()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" + ], + "text/plain": [ + "NearestNeighbors()" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "knn = cuml.NearestNeighbors(n_neighbors=1)\n", + "knn.fit(all_med[['northing', 'easting']])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save every infected member in `df` into a new dataframe called `infected_df`.\n", + "\n", + "**Tip**: Reset the index of `infected_df` with `.reset_index(drop=True)`. " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
latlonginfected
053.715826-2.4300791.0
153.664881-2.4256731.0
253.696765-2.4889401.0
353.696966-2.4888971.0
453.727804-2.3929591.0
............
7087551.662717-2.9268501.0
7087651.599350-2.9591751.0
7087751.543825-2.8229841.0
7087851.562536-2.8794921.0
7087951.628748-2.8371511.0
\n", + "

70880 rows × 3 columns

\n", + "
" + ], + "text/plain": [ + " lat long infected\n", + "0 53.715826 -2.430079 1.0\n", + "1 53.664881 -2.425673 1.0\n", + "2 53.696765 -2.488940 1.0\n", + "3 53.696966 -2.488897 1.0\n", + "4 53.727804 -2.392959 1.0\n", + "... ... ... ...\n", + "70875 51.662717 -2.926850 1.0\n", + "70876 51.599350 -2.959175 1.0\n", + "70877 51.543825 -2.822984 1.0\n", + "70878 51.562536 -2.879492 1.0\n", + "70879 51.628748 -2.837151 1.0\n", + "\n", + "[70880 rows x 3 columns]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "infected_filter = df['infected']==1\n", + "infected_df = df[infected_filter]\n", + "infected_df.reset_index(drop=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create `northing` and `easting` values for `infected_df`." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
latlonginfectednorthingeasting
134658653.715826-2.4300791.0424489.783814371619.678741
135093253.664881-2.4256731.0418820.687944371876.492369
135208553.696765-2.4889401.0422394.398940367721.000265
135279953.696966-2.4888971.0422416.821887367723.973098
135752953.727804-2.3929591.0425808.109929374076.557677
..................
5845918951.662717-2.9268501.0196451.131712335900.971171
5845955151.599350-2.9591751.0189433.449408333573.002864
5846193551.543825-2.8229841.0183143.984735342935.130365
5846408251.562536-2.8794921.0185270.296666339042.062616
5846420951.628748-2.8371511.0192598.790941342060.980289
\n", + "

70880 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " lat long infected northing easting\n", + "1346586 53.715826 -2.430079 1.0 424489.783814 371619.678741\n", + "1350932 53.664881 -2.425673 1.0 418820.687944 371876.492369\n", + "1352085 53.696765 -2.488940 1.0 422394.398940 367721.000265\n", + "1352799 53.696966 -2.488897 1.0 422416.821887 367723.973098\n", + "1357529 53.727804 -2.392959 1.0 425808.109929 374076.557677\n", + "... ... ... ... ... ...\n", + "58459189 51.662717 -2.926850 1.0 196451.131712 335900.971171\n", + "58459551 51.599350 -2.959175 1.0 189433.449408 333573.002864\n", + "58461935 51.543825 -2.822984 1.0 183143.984735 342935.130365\n", + "58464082 51.562536 -2.879492 1.0 185270.296666 339042.062616\n", + "58464209 51.628748 -2.837151 1.0 192598.790941 342060.980289\n", + "\n", + "[70880 rows x 5 columns]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cupy_infected_lat = cp.asarray(infected_df['lat'])\n", + "cupy_infected_long = cp.asarray(infected_df['long'])\n", + "\n", + "infected_df['northing'], infected_df['easting'] = latlong2osgbgrid_cupy(cupy_infected_lat, cupy_infected_long)\n", + "infected_df" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Use `knn.kneighbors` with `n_neighbors=1` on `infected_df`'s `northing` and `easting` values. Save the return values in `distances` and `indices`." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
latlonginfectednorthingeastingdistanceclosest_clinic_hospital
134658653.715826-2.4300791.0424489.783814371619.6787412562.83007818316
135093253.664881-2.4256731.0418820.687944371876.4923692988.61816412816
135208553.696765-2.4889401.0422394.398940367721.0002651162.6850597785
135279953.696966-2.4888971.0422416.821887367723.9730981162.2832037785
135752953.727804-2.3929591.0425808.109929374076.5576771455.1156014962
........................
5845918951.662717-2.9268501.0196451.131712335900.9711718617.32421910015
5845955151.599350-2.9591751.0189433.449408333573.0028641306.97924810015
5846193551.543825-2.8229841.0183143.984735342935.1303657633.2954103814
5846408251.562536-2.8794921.0185270.296666339042.0626167071.36230510015
5846420951.628748-2.8371511.0192598.790941342060.98028910222.64355510015
\n", + "

70880 rows × 7 columns

\n", + "
" + ], + "text/plain": [ + " lat long infected northing easting \\\n", + "1346586 53.715826 -2.430079 1.0 424489.783814 371619.678741 \n", + "1350932 53.664881 -2.425673 1.0 418820.687944 371876.492369 \n", + "1352085 53.696765 -2.488940 1.0 422394.398940 367721.000265 \n", + "1352799 53.696966 -2.488897 1.0 422416.821887 367723.973098 \n", + "1357529 53.727804 -2.392959 1.0 425808.109929 374076.557677 \n", + "... ... ... ... ... ... \n", + "58459189 51.662717 -2.926850 1.0 196451.131712 335900.971171 \n", + "58459551 51.599350 -2.959175 1.0 189433.449408 333573.002864 \n", + "58461935 51.543825 -2.822984 1.0 183143.984735 342935.130365 \n", + "58464082 51.562536 -2.879492 1.0 185270.296666 339042.062616 \n", + "58464209 51.628748 -2.837151 1.0 192598.790941 342060.980289 \n", + "\n", + " distance closest_clinic_hospital \n", + "1346586 2562.830078 18316 \n", + "1350932 2988.618164 12816 \n", + "1352085 1162.685059 7785 \n", + "1352799 1162.283203 7785 \n", + "1357529 1455.115601 4962 \n", + "... ... ... \n", + "58459189 8617.324219 10015 \n", + "58459551 1306.979248 10015 \n", + "58461935 7633.295410 3814 \n", + "58464082 7071.362305 10015 \n", + "58464209 10222.643555 10015 \n", + "\n", + "[70880 rows x 7 columns]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "neigh = infected_df[['northing', 'easting']]\n", + "\n", + "distances, indices = knn.kneighbors(neigh, n_neighbors=1)\n", + "infected_df['distance']=distances\n", + "infected_df['closest_clinic_hospital']=indices\n", + "infected_df" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### View Closest Clinic/Hospital ###" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`indices`, returned from your use of `knn.kneighbors` immediately above, should map person indices to their closest clinic/hospital indices:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here you can print an infected individual's coordinates from `infected_df`:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "lat 53.715826\n", + "long -2.430079\n", + "infected 1.000000\n", + "northing 424489.783814\n", + "easting 371619.678741\n", + "distance 2562.830078\n", + "closest_clinic_hospital 18316.000000\n", + "Name: 1346586, dtype: float64" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "infected_df.iloc[0] # get the coords of an infected individual (in this case, individual 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You should be able to used the mapped index for the nearest facility to see that indeed the nearest facility is at a nearby coordinate:" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OrganisationIDOrganisationCodeOrganisationTypeSubTypeSectorOrganisationStatusIsPimsManagedOrganisationNameAddress1Address2...LatitudeLongitudeParentODSCodeParentNamePhoneEmailWebsiteFaxnorthingeasting
183169445963NPR0FClinicUNKNOWN<NA>VisibleFalseCommunity Dermatology Service - About HealthThe Innovation Centre1 Evolution Park...53.733227-2.455536<NA><NA><NA><NA><NA><NA>426435.969251369952.220236
128164209876NBG84ClinicUNKNOWN<NA>VisibleFalseMediscan - Edgworth Medical Centre354 Bolton RoadEdgworth...53.646824-2.392187<NA><NA><NA><NA><NA><NA>416799.229665374077.751691
778576801NYNFDClinicUNKNOWN<NA>VisibleFalseSpecsavers Hearcare - Lancashire - DarwenDarwen Health CentreJames Street West...53.695747-2.471412<NA><NA><NA><NA><NA><NA>422273.431827368877.384334
778576801NYNFDClinicUNKNOWN<NA>VisibleFalseSpecsavers Hearcare - Lancashire - DarwenDarwen Health CentreJames Street West...53.695747-2.471412<NA><NA><NA><NA><NA><NA>422273.431827368877.384334
496265435RXR57ClinicUNKNOWN<NA>VisibleFalseStonebridge House SurgeryHeys LaneOswaldtwistle...53.740868-2.394079<NA><NA><NA><NA><NA><NA>427261.739714374010.710918
..................................................................
100151095623NTN57ClinicUNKNOWN<NA>VisibleTruePriory Mount Eveswell<NA>22 Eveswell Park Road...51.590332-2.971274<NA><NA>01633 271 784mounteveswell@priorygroup.comhttp://www.priorygroup.com/01633 277 509188441.704765332721.739274
100151095623NTN57ClinicUNKNOWN<NA>VisibleTruePriory Mount Eveswell<NA>22 Eveswell Park Road...51.590332-2.971274<NA><NA>01633 271 784mounteveswell@priorygroup.comhttp://www.priorygroup.com/01633 277 509188441.704765332721.739274
381462305NYNE8ClinicUNKNOWN<NA>VisibleFalseSpecsavers Hearcare - North Somerset - Portishead7 The PrecinctPortishead...51.484352-2.768061<NA><NA><NA><NA><NA><NA>176489.080200346674.024103
100151095623NTN57ClinicUNKNOWN<NA>VisibleTruePriory Mount Eveswell<NA>22 Eveswell Park Road...51.590332-2.971274<NA><NA>01633 271 784mounteveswell@priorygroup.comhttp://www.priorygroup.com/01633 277 509188441.704765332721.739274
100151095623NTN57ClinicUNKNOWN<NA>VisibleTruePriory Mount Eveswell<NA>22 Eveswell Park Road...51.590332-2.971274<NA><NA>01633 271 784mounteveswell@priorygroup.comhttp://www.priorygroup.com/01633 277 509188441.704765332721.739274
\n", + "

70880 rows × 24 columns

\n", + "
" + ], + "text/plain": [ + " OrganisationID OrganisationCode OrganisationType SubType Sector \\\n", + "18316 9445963 NPR0F Clinic UNKNOWN \n", + "12816 4209876 NBG84 Clinic UNKNOWN \n", + "7785 76801 NYNFD Clinic UNKNOWN \n", + "7785 76801 NYNFD Clinic UNKNOWN \n", + "4962 65435 RXR57 Clinic UNKNOWN \n", + "... ... ... ... ... ... \n", + "10015 1095623 NTN57 Clinic UNKNOWN \n", + "10015 1095623 NTN57 Clinic UNKNOWN \n", + "3814 62305 NYNE8 Clinic UNKNOWN \n", + "10015 1095623 NTN57 Clinic UNKNOWN \n", + "10015 1095623 NTN57 Clinic UNKNOWN \n", + "\n", + " OrganisationStatus IsPimsManaged \\\n", + "18316 Visible False \n", + "12816 Visible False \n", + "7785 Visible False \n", + "7785 Visible False \n", + "4962 Visible False \n", + "... ... ... \n", + "10015 Visible True \n", + "10015 Visible True \n", + "3814 Visible False \n", + "10015 Visible True \n", + "10015 Visible True \n", + "\n", + " OrganisationName \\\n", + "18316 Community Dermatology Service - About Health \n", + "12816 Mediscan - Edgworth Medical Centre \n", + "7785 Specsavers Hearcare - Lancashire - Darwen \n", + "7785 Specsavers Hearcare - Lancashire - Darwen \n", + "4962 Stonebridge House Surgery \n", + "... ... \n", + "10015 Priory Mount Eveswell \n", + "10015 Priory Mount Eveswell \n", + "3814 Specsavers Hearcare - North Somerset - Portishead \n", + "10015 Priory Mount Eveswell \n", + "10015 Priory Mount Eveswell \n", + "\n", + " Address1 Address2 ... Latitude \\\n", + "18316 The Innovation Centre 1 Evolution Park ... 53.733227 \n", + "12816 354 Bolton Road Edgworth ... 53.646824 \n", + "7785 Darwen Health Centre James Street West ... 53.695747 \n", + "7785 Darwen Health Centre James Street West ... 53.695747 \n", + "4962 Heys Lane Oswaldtwistle ... 53.740868 \n", + "... ... ... ... ... \n", + "10015 22 Eveswell Park Road ... 51.590332 \n", + "10015 22 Eveswell Park Road ... 51.590332 \n", + "3814 7 The Precinct Portishead ... 51.484352 \n", + "10015 22 Eveswell Park Road ... 51.590332 \n", + "10015 22 Eveswell Park Road ... 51.590332 \n", + "\n", + " Longitude ParentODSCode ParentName Phone \\\n", + "18316 -2.455536 \n", + "12816 -2.392187 \n", + "7785 -2.471412 \n", + "7785 -2.471412 \n", + "4962 -2.394079 \n", + "... ... ... ... ... \n", + "10015 -2.971274 01633 271 784 \n", + "10015 -2.971274 01633 271 784 \n", + "3814 -2.768061 \n", + "10015 -2.971274 01633 271 784 \n", + "10015 -2.971274 01633 271 784 \n", + "\n", + " Email Website \\\n", + "18316 \n", + "12816 \n", + "7785 \n", + "7785 \n", + "4962 \n", + "... ... ... \n", + "10015 mounteveswell@priorygroup.com http://www.priorygroup.com/ \n", + "10015 mounteveswell@priorygroup.com http://www.priorygroup.com/ \n", + "3814 \n", + "10015 mounteveswell@priorygroup.com http://www.priorygroup.com/ \n", + "10015 mounteveswell@priorygroup.com http://www.priorygroup.com/ \n", + "\n", + " Fax northing easting \n", + "18316 426435.969251 369952.220236 \n", + "12816 416799.229665 374077.751691 \n", + "7785 422273.431827 368877.384334 \n", + "7785 422273.431827 368877.384334 \n", + "4962 427261.739714 374010.710918 \n", + "... ... ... ... \n", + "10015 01633 277 509 188441.704765 332721.739274 \n", + "10015 01633 277 509 188441.704765 332721.739274 \n", + "3814 176489.080200 346674.024103 \n", + "10015 01633 277 509 188441.704765 332721.739274 \n", + "10015 01633 277 509 188441.704765 332721.739274 \n", + "\n", + "[70880 rows x 24 columns]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_med.iloc[infected_df['closest_clinic_hospital']] # printing the entry for facility 1234 (replace with the index identified as closest to the individual)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## New Patients ##" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Use the `knn` model to find the closest clinic/hospital for the below new patients. " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namenorthingeastingdistanceclosest_clinic_hospitalOrganisationID
0John Smith462643.228292363859.7580577286.685059463764351
1Greg Brown409324.103047464084.5085061561.915405388662389
\n", + "
" + ], + "text/plain": [ + " name northing easting distance \\\n", + "0 John Smith 462643.228292 363859.758057 7286.685059 \n", + "1 Greg Brown 409324.103047 464084.508506 1561.915405 \n", + "\n", + " closest_clinic_hospital OrganisationID \n", + "0 4637 64351 \n", + "1 3886 62389 " + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# DO NOT CHANGE THIS CELL\n", + "patients=[\n", + " {\n", + " \"name\":\"John Smith\", \n", + " \"northing\":462643.2282915547,\n", + " \"easting\":363859.7580565622\n", + " }, \n", + " {\n", + " \"name\":\"Greg Brown\", \n", + " \"northing\":409324.1030472915,\n", + " \"easting\":464084.5085059871\n", + " }\n", + "]\n", + "\n", + "patients_df=pd.DataFrame(patients)\n", + "\n", + "patients_df['distance'], patients_df['closest_clinic_hospital'] = knn.kneighbors(patients_df[['northing', 'easting']])\n", + "\n", + "patients_df['OrganisationID'] = patients_df.apply(lambda x: all_med.loc[x['closest_clinic_hospital'], \"OrganisationID\"], axis=1)\n", + "\n", + "patients_df" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/opt/conda/lib/python3.10/site-packages/cudf/io/json.py:194: UserWarning: Using CPU via Pandas to write JSON dataset\n", + " warnings.warn(\"Using CPU via Pandas to write JSON dataset\")\n" + ] + } + ], + "source": [ + "patients_df.to_json('my_assessment/question_2.json', orient='records')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Check Submission ##" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{\"name\":\"John Smith\",\"northing\":462643.2282915547,\"easting\":363859.7580565622,\"distance\":7286.6850585938,\"closest_clinic_hospital\":4637,\"OrganisationID\":64351},{\"name\":\"Greg Brown\",\"northing\":409324.1030472915,\"easting\":464084.5085059871,\"distance\":1561.9154052734,\"closest_clinic_hospital\":3886,\"OrganisationID\":62389}]" + ] + } + ], + "source": [ + "!cat my_assessment/question_2.json" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Tip**: Your submission file should contain one line of text, similar to: \n", + "\n", + "```\n", + "[{'name':'John Smith','northing':XXX.XX,'easting':XXX.XX,'closest_clinic_hospital':XX,'OrganisationID':XX},{'name':'Greg Brown','northing':XXX.XX,'easting':XXX.XX,'closest_clinic_hospital':XX,'OrganisationID':XX}]\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Please Restart the Kernel

" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "...before moving to the next notebook." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'status': 'ok', 'restart': True}" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import IPython\n", + "app = IPython.Application.instance()\n", + "app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"Header\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.15" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} -- cgit v1.2.3