{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://www.nvidia.com/dli\"><img src=\"images/DLI_Header.png\" alt=\"Header\" style=\"width: 400px;\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Week 2: Identify Nearest Health Facilities"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<span style=\"color:red\">\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",
    "</span>\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": 5,
   "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": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>long</th>\n",
       "      <th>infected</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>54.522511</td>\n",
       "      <td>-1.571896</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>54.554031</td>\n",
       "      <td>-1.524968</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>54.552483</td>\n",
       "      <td>-1.435203</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54.537186</td>\n",
       "      <td>-1.566215</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>54.528210</td>\n",
       "      <td>-1.588462</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58479889</th>\n",
       "      <td>51.634418</td>\n",
       "      <td>-2.925863</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58479890</th>\n",
       "      <td>51.556969</td>\n",
       "      <td>-3.036290</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58479891</th>\n",
       "      <td>51.588997</td>\n",
       "      <td>-2.921915</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58479892</th>\n",
       "      <td>51.590973</td>\n",
       "      <td>-2.954540</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58479893</th>\n",
       "      <td>51.576717</td>\n",
       "      <td>-2.952142</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>58479894 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                lat      long infected\n",
       "0         54.522511 -1.571896      0.0\n",
       "1         54.554031 -1.524968      0.0\n",
       "2         54.552483 -1.435203      0.0\n",
       "3         54.537186 -1.566215      0.0\n",
       "4         54.528210 -1.588462      0.0\n",
       "...             ...       ...      ...\n",
       "58479889  51.634418 -2.925863      0.0\n",
       "58479890  51.556969 -3.036290      0.0\n",
       "58479891  51.588997 -2.921915      0.0\n",
       "58479892  51.590973 -2.954540      0.0\n",
       "58479893  51.576717 -2.952142      0.0\n",
       "\n",
       "[58479894 rows x 3 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./data/week2.csv', dtype = {\n",
    "    'lat': 'float32',\n",
    "    'long': 'float32',\n",
    "    'infected': 'category',\n",
    "}, 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": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OrganisationID</th>\n",
       "      <th>OrganisationCode</th>\n",
       "      <th>OrganisationType</th>\n",
       "      <th>SubType</th>\n",
       "      <th>Sector</th>\n",
       "      <th>OrganisationStatus</th>\n",
       "      <th>IsPimsManaged</th>\n",
       "      <th>OrganisationName</th>\n",
       "      <th>Address1</th>\n",
       "      <th>Address2</th>\n",
       "      <th>...</th>\n",
       "      <th>County</th>\n",
       "      <th>Postcode</th>\n",
       "      <th>Latitude</th>\n",
       "      <th>Longitude</th>\n",
       "      <th>ParentODSCode</th>\n",
       "      <th>ParentName</th>\n",
       "      <th>Phone</th>\n",
       "      <th>Email</th>\n",
       "      <th>Website</th>\n",
       "      <th>Fax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17970</td>\n",
       "      <td>NDA07</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Walton Community Hospital - Virgin Care Servic...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Rodney Road</td>\n",
       "      <td>...</td>\n",
       "      <td>Surrey</td>\n",
       "      <td>KT12 3LD</td>\n",
       "      <td>51.37999725</td>\n",
       "      <td>-0.406042069</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01932 414205</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>01932 253674</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17981</td>\n",
       "      <td>NDA18</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Woking Community Hospital (Virgin Care)</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Heathside Road</td>\n",
       "      <td>...</td>\n",
       "      <td>Surrey</td>\n",
       "      <td>GU22 7HS</td>\n",
       "      <td>51.31513214</td>\n",
       "      <td>-0.556289494</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01483 715911</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>18102</td>\n",
       "      <td>NLT02</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>NHS Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>Old Street</td>\n",
       "      <td>...</td>\n",
       "      <td>Avon</td>\n",
       "      <td>BS21 6BS</td>\n",
       "      <td>51.43719482</td>\n",
       "      <td>-2.847192764</td>\n",
       "      <td>NLT</td>\n",
       "      <td>North Somerset Community Partnership Community...</td>\n",
       "      <td>01275 872212</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>http://www.nscphealth.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>18138</td>\n",
       "      <td>NMP01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Bridgewater Hospital</td>\n",
       "      <td>120 Princess Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>Greater Manchester</td>\n",
       "      <td>M15 5AT</td>\n",
       "      <td>53.4597435</td>\n",
       "      <td>-2.245468855</td>\n",
       "      <td>NMP</td>\n",
       "      <td>Bridgewater Hospital (Manchester) Ltd</td>\n",
       "      <td>0161 2270000</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>www.bridgewaterhospital.com</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18142</td>\n",
       "      <td>NMV01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Kneesworth House</td>\n",
       "      <td>Old North Road</td>\n",
       "      <td>Bassingbourn</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>SG8 5JP</td>\n",
       "      <td>52.07812119</td>\n",
       "      <td>-0.030604055</td>\n",
       "      <td>NMV</td>\n",
       "      <td>Partnerships In Care Ltd</td>\n",
       "      <td>01763 255 700</td>\n",
       "      <td>reception_kneesworthhouse@partnershipsincare.c...</td>\n",
       "      <td>www.partnershipsincare.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1224</th>\n",
       "      <td>10617466</td>\n",
       "      <td>RTH18</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>University Hospital Of Wales</td>\n",
       "      <td>C/O John Radcliffe Hospital</td>\n",
       "      <td>Headley Way</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>OX3 9DU</td>\n",
       "      <td>51.76387405</td>\n",
       "      <td>-1.219792008</td>\n",
       "      <td>RTH</td>\n",
       "      <td>Oxford University Hospitals NHS Foundation Trust</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1225</th>\n",
       "      <td>10617482</td>\n",
       "      <td>RX3KI</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Foss Park Hospital</td>\n",
       "      <td>Huntington House</td>\n",
       "      <td>Jockey Lane</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>YO32 9XW</td>\n",
       "      <td>53.98666382</td>\n",
       "      <td>-1.051122308</td>\n",
       "      <td>RX3</td>\n",
       "      <td>Tees, Esk and Wear Valleys NHS Foundation Trust</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1226</th>\n",
       "      <td>10617567</td>\n",
       "      <td>RGT1W</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Jersey General Hospital</td>\n",
       "      <td>The Parade</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>JE1 3UH</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>RGT</td>\n",
       "      <td>Cambridge University Hospitals NHS Foundation ...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1227</th>\n",
       "      <td>10617714</td>\n",
       "      <td>RAX0A</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>London North West University Hospitals</td>\n",
       "      <td>Watford Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>HA1 3UJ</td>\n",
       "      <td>51.57540894</td>\n",
       "      <td>-0.322022736</td>\n",
       "      <td>RAX</td>\n",
       "      <td>Kingston Hospital NHS Foundation Trust</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1228</th>\n",
       "      <td>10617726</td>\n",
       "      <td>RDU5A</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>John Radcliffe Hospital</td>\n",
       "      <td>Headley Way</td>\n",
       "      <td>Headington</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>OX3 9DU</td>\n",
       "      <td>51.76387405</td>\n",
       "      <td>-1.219792008</td>\n",
       "      <td>RDU</td>\n",
       "      <td>Frimley Health NHS Foundation Trust</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1229 rows × 22 columns</p>\n",
       "</div>"
      ],
      "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                                  <NA>     Rodney Road  ...   \n",
       "1                                  <NA>  Heathside Road  ...   \n",
       "2     North Somerset Community Hospital      Old Street  ...   \n",
       "3                     120 Princess Road            <NA>  ...   \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            <NA>  ...   \n",
       "1227                       Watford Road            <NA>  ...   \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                   <NA>   SG8 5JP  52.07812119  -0.030604055           NMV   \n",
       "...                  ...       ...          ...           ...           ...   \n",
       "1224                <NA>   OX3 9DU  51.76387405  -1.219792008           RTH   \n",
       "1225                <NA>  YO32 9XW  53.98666382  -1.051122308           RX3   \n",
       "1226                <NA>   JE1 3UH         <NA>          <NA>           RGT   \n",
       "1227                <NA>   HA1 3UJ  51.57540894  -0.322022736           RAX   \n",
       "1228                <NA>   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           <NA>   \n",
       "1225    Tees, Esk and Wear Valleys NHS Foundation Trust           <NA>   \n",
       "1226  Cambridge University Hospitals NHS Foundation ...           <NA>   \n",
       "1227             Kingston Hospital NHS Foundation Trust           <NA>   \n",
       "1228                Frimley Health NHS Foundation Trust           <NA>   \n",
       "\n",
       "                                                  Email  \\\n",
       "0                                                  <NA>   \n",
       "1                                                  <NA>   \n",
       "2                                                  <NA>   \n",
       "3                                                  <NA>   \n",
       "4     reception_kneesworthhouse@partnershipsincare.c...   \n",
       "...                                                 ...   \n",
       "1224                                               <NA>   \n",
       "1225                                               <NA>   \n",
       "1226                                               <NA>   \n",
       "1227                                               <NA>   \n",
       "1228                                               <NA>   \n",
       "\n",
       "                           Website           Fax  \n",
       "0                             <NA>  01932 253674  \n",
       "1                             <NA>          <NA>  \n",
       "2      http://www.nscphealth.co.uk          <NA>  \n",
       "3      www.bridgewaterhospital.com          <NA>  \n",
       "4     www.partnershipsincare.co.uk          <NA>  \n",
       "...                            ...           ...  \n",
       "1224                          <NA>          <NA>  \n",
       "1225                          <NA>          <NA>  \n",
       "1226                          <NA>          <NA>  \n",
       "1227                          <NA>          <NA>  \n",
       "1228                          <NA>          <NA>  \n",
       "\n",
       "[1229 rows x 22 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hospitals_df = pd.read_csv('./data/hospitals.csv')\n",
    "hospitals_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OrganisationID</th>\n",
       "      <th>OrganisationCode</th>\n",
       "      <th>OrganisationType</th>\n",
       "      <th>SubType</th>\n",
       "      <th>OrganisationStatus</th>\n",
       "      <th>IsPimsManaged</th>\n",
       "      <th>OrganisationName</th>\n",
       "      <th>Address1</th>\n",
       "      <th>Address2</th>\n",
       "      <th>Address3</th>\n",
       "      <th>City</th>\n",
       "      <th>County</th>\n",
       "      <th>Postcode</th>\n",
       "      <th>Latitude</th>\n",
       "      <th>Longitude</th>\n",
       "      <th>Phone</th>\n",
       "      <th>Email</th>\n",
       "      <th>Website</th>\n",
       "      <th>Fax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12366</td>\n",
       "      <td>F81157</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Frinton Road Medical Centre</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>68 Frinton Road, Hollond-on-Sea</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Clacton-on-Sea</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>CO15 5UW</td>\n",
       "      <td>51.804237</td>\n",
       "      <td>1.186376</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12450</td>\n",
       "      <td>F81670</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Epping Close Surgery</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Epping Close</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Clacton on Sea</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>CO15 4UZ</td>\n",
       "      <td>51.815262</td>\n",
       "      <td>1.154707</td>\n",
       "      <td>01255 222668</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12461</td>\n",
       "      <td>F81681</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Green Elms Medical Centre</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>32 Crossways</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Jaywick, Clacton on Sea</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>CO15 2NB</td>\n",
       "      <td>51.780621</td>\n",
       "      <td>1.117907</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17937</td>\n",
       "      <td>NAA01</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>St Chads Clinic</td>\n",
       "      <td>St. Chads Drive</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Liverpool</td>\n",
       "      <td>Merseyside</td>\n",
       "      <td>L32 8RE</td>\n",
       "      <td>53.482368</td>\n",
       "      <td>-2.885404</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>17938</td>\n",
       "      <td>NAA02</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Whiston Health Centre</td>\n",
       "      <td>Old Colliery Road</td>\n",
       "      <td>Whiston</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Prescot</td>\n",
       "      <td>Merseyside</td>\n",
       "      <td>L35 3SX</td>\n",
       "      <td>53.415630</td>\n",
       "      <td>-2.800874</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19077</th>\n",
       "      <td>10617742</td>\n",
       "      <td>NBG7L</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Sunnybank Medical Centre</td>\n",
       "      <td>Town Gate</td>\n",
       "      <td>Wyke</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Bradford</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BD12 9NG</td>\n",
       "      <td>53.737923</td>\n",
       "      <td>-1.767982</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19078</th>\n",
       "      <td>10617743</td>\n",
       "      <td>NFH02</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Mendip Vale Medi...</td>\n",
       "      <td>Pudding Pie Lane</td>\n",
       "      <td>Langford</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Bristol</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS40 5EL</td>\n",
       "      <td>51.341579</td>\n",
       "      <td>-2.784808</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19079</th>\n",
       "      <td>10617744</td>\n",
       "      <td>NFH03</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Axbridge Medical...</td>\n",
       "      <td>Houlgate Way</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Axbridge</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS26 2BJ</td>\n",
       "      <td>51.286285</td>\n",
       "      <td>-2.820388</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19080</th>\n",
       "      <td>10617746</td>\n",
       "      <td>NEMAM</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Lawton House Surgery</td>\n",
       "      <td>Bromley Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Congleton</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>CW12 1QG</td>\n",
       "      <td>53.163048</td>\n",
       "      <td>-2.205781</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19081</th>\n",
       "      <td>10617747</td>\n",
       "      <td>NFH04</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Wedmore Medical ...</td>\n",
       "      <td>St. Medard Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Wedmore</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS28 4AY</td>\n",
       "      <td>51.227219</td>\n",
       "      <td>-2.816258</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>19082 rows × 19 columns</p>\n",
       "</div>"
      ],
      "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               <NA>   \n",
       "1                                   Epping Close Surgery               <NA>   \n",
       "2                              Green Elms Medical Centre               <NA>   \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     <NA>           Clacton-on-Sea   \n",
       "1                         Epping Close     <NA>           Clacton on Sea   \n",
       "2                         32 Crossways     <NA>  Jaywick, Clacton on Sea   \n",
       "3                                 <NA>     <NA>                Liverpool   \n",
       "4                              Whiston     <NA>                  Prescot   \n",
       "...                                ...      ...                      ...   \n",
       "19077                             Wyke     <NA>                 Bradford   \n",
       "19078                         Langford     <NA>                  Bristol   \n",
       "19079                             <NA>     <NA>                 Axbridge   \n",
       "19080                             <NA>     <NA>                Congleton   \n",
       "19081                             <NA>     <NA>                  Wedmore   \n",
       "\n",
       "           County  Postcode   Latitude  Longitude         Phone Email Website  \\\n",
       "0            <NA>  CO15 5UW  51.804237   1.186376          <NA>  <NA>    <NA>   \n",
       "1            <NA>  CO15 4UZ  51.815262   1.154707  01255 222668  <NA>    <NA>   \n",
       "2            <NA>  CO15 2NB  51.780621   1.117907          <NA>  <NA>    <NA>   \n",
       "3      Merseyside   L32 8RE  53.482368  -2.885404          <NA>  <NA>    <NA>   \n",
       "4      Merseyside   L35 3SX  53.415630  -2.800874          <NA>  <NA>    <NA>   \n",
       "...           ...       ...        ...        ...           ...   ...     ...   \n",
       "19077        <NA>  BD12 9NG  53.737923  -1.767982          <NA>  <NA>    <NA>   \n",
       "19078        <NA>  BS40 5EL  51.341579  -2.784808          <NA>  <NA>    <NA>   \n",
       "19079        <NA>  BS26 2BJ  51.286285  -2.820388          <NA>  <NA>    <NA>   \n",
       "19080        <NA>  CW12 1QG  53.163048  -2.205781          <NA>  <NA>    <NA>   \n",
       "19081        <NA>  BS28 4AY  51.227219  -2.816258          <NA>  <NA>    <NA>   \n",
       "\n",
       "        Fax  \n",
       "0      <NA>  \n",
       "1      <NA>  \n",
       "2      <NA>  \n",
       "3      <NA>  \n",
       "4      <NA>  \n",
       "...     ...  \n",
       "19077  <NA>  \n",
       "19078  <NA>  \n",
       "19079  <NA>  \n",
       "19080  <NA>  \n",
       "19081  <NA>  \n",
       "\n",
       "[19082 rows x 19 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clinics_df = pd.read_csv('./data/clinics.csv')\n",
    "clinics_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OrganisationID</th>\n",
       "      <th>OrganisationCode</th>\n",
       "      <th>OrganisationType</th>\n",
       "      <th>SubType</th>\n",
       "      <th>Sector</th>\n",
       "      <th>OrganisationStatus</th>\n",
       "      <th>IsPimsManaged</th>\n",
       "      <th>OrganisationName</th>\n",
       "      <th>Address1</th>\n",
       "      <th>Address2</th>\n",
       "      <th>...</th>\n",
       "      <th>County</th>\n",
       "      <th>Postcode</th>\n",
       "      <th>Latitude</th>\n",
       "      <th>Longitude</th>\n",
       "      <th>ParentODSCode</th>\n",
       "      <th>ParentName</th>\n",
       "      <th>Phone</th>\n",
       "      <th>Email</th>\n",
       "      <th>Website</th>\n",
       "      <th>Fax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17970</td>\n",
       "      <td>NDA07</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Walton Community Hospital - Virgin Care Servic...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Rodney Road</td>\n",
       "      <td>...</td>\n",
       "      <td>Surrey</td>\n",
       "      <td>KT12 3LD</td>\n",
       "      <td>51.379997</td>\n",
       "      <td>-0.406042</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01932 414205</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>01932 253674</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17981</td>\n",
       "      <td>NDA18</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Woking Community Hospital (Virgin Care)</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Heathside Road</td>\n",
       "      <td>...</td>\n",
       "      <td>Surrey</td>\n",
       "      <td>GU22 7HS</td>\n",
       "      <td>51.315132</td>\n",
       "      <td>-0.556289</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01483 715911</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>18102</td>\n",
       "      <td>NLT02</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>NHS Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>Old Street</td>\n",
       "      <td>...</td>\n",
       "      <td>Avon</td>\n",
       "      <td>BS21 6BS</td>\n",
       "      <td>51.437195</td>\n",
       "      <td>-2.847193</td>\n",
       "      <td>NLT</td>\n",
       "      <td>North Somerset Community Partnership Community...</td>\n",
       "      <td>01275 872212</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>http://www.nscphealth.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>18138</td>\n",
       "      <td>NMP01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Bridgewater Hospital</td>\n",
       "      <td>120 Princess Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>Greater Manchester</td>\n",
       "      <td>M15 5AT</td>\n",
       "      <td>53.459743</td>\n",
       "      <td>-2.245469</td>\n",
       "      <td>NMP</td>\n",
       "      <td>Bridgewater Hospital (Manchester) Ltd</td>\n",
       "      <td>0161 2270000</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>www.bridgewaterhospital.com</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18142</td>\n",
       "      <td>NMV01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Kneesworth House</td>\n",
       "      <td>Old North Road</td>\n",
       "      <td>Bassingbourn</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>SG8 5JP</td>\n",
       "      <td>52.078121</td>\n",
       "      <td>-0.030604</td>\n",
       "      <td>NMV</td>\n",
       "      <td>Partnerships In Care Ltd</td>\n",
       "      <td>01763 255 700</td>\n",
       "      <td>reception_kneesworthhouse@partnershipsincare.c...</td>\n",
       "      <td>www.partnershipsincare.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19077</th>\n",
       "      <td>10617742</td>\n",
       "      <td>NBG7L</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Sunnybank Medical Centre</td>\n",
       "      <td>Town Gate</td>\n",
       "      <td>Wyke</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BD12 9NG</td>\n",
       "      <td>53.737923</td>\n",
       "      <td>-1.767982</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19078</th>\n",
       "      <td>10617743</td>\n",
       "      <td>NFH02</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Mendip Vale Medi...</td>\n",
       "      <td>Pudding Pie Lane</td>\n",
       "      <td>Langford</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS40 5EL</td>\n",
       "      <td>51.341579</td>\n",
       "      <td>-2.784808</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19079</th>\n",
       "      <td>10617744</td>\n",
       "      <td>NFH03</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Axbridge Medical...</td>\n",
       "      <td>Houlgate Way</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS26 2BJ</td>\n",
       "      <td>51.286285</td>\n",
       "      <td>-2.820388</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19080</th>\n",
       "      <td>10617746</td>\n",
       "      <td>NEMAM</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Lawton House Surgery</td>\n",
       "      <td>Bromley Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>CW12 1QG</td>\n",
       "      <td>53.163048</td>\n",
       "      <td>-2.205781</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19081</th>\n",
       "      <td>10617747</td>\n",
       "      <td>NFH04</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Wedmore Medical ...</td>\n",
       "      <td>St. Medard Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS28 4AY</td>\n",
       "      <td>51.227219</td>\n",
       "      <td>-2.816258</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20311 rows × 22 columns</p>\n",
       "</div>"
      ],
      "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                <NA>            Visible          False   \n",
       "19078                <NA>            Visible          False   \n",
       "19079                <NA>            Visible          False   \n",
       "19080                <NA>            Visible          False   \n",
       "19081                <NA>            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                                   <NA>     Rodney Road  ...   \n",
       "1                                   <NA>  Heathside Road  ...   \n",
       "2      North Somerset Community Hospital      Old Street  ...   \n",
       "3                      120 Princess Road            <NA>  ...   \n",
       "4                         Old North Road    Bassingbourn  ...   \n",
       "...                                  ...             ...  ...   \n",
       "19077                          Town Gate            Wyke  ...   \n",
       "19078                   Pudding Pie Lane        Langford  ...   \n",
       "19079                       Houlgate Way            <NA>  ...   \n",
       "19080                       Bromley Road            <NA>  ...   \n",
       "19081                    St. Medard Road            <NA>  ...   \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                    <NA>   SG8 5JP  52.078121  -0.030604            NMV   \n",
       "...                   ...       ...        ...        ...            ...   \n",
       "19077                <NA>  BD12 9NG  53.737923  -1.767982           <NA>   \n",
       "19078                <NA>  BS40 5EL  51.341579  -2.784808           <NA>   \n",
       "19079                <NA>  BS26 2BJ  51.286285  -2.820388           <NA>   \n",
       "19080                <NA>  CW12 1QG  53.163048  -2.205781           <NA>   \n",
       "19081                <NA>  BS28 4AY  51.227219  -2.816258           <NA>   \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                                               <NA>           <NA>   \n",
       "19078                                               <NA>           <NA>   \n",
       "19079                                               <NA>           <NA>   \n",
       "19080                                               <NA>           <NA>   \n",
       "19081                                               <NA>           <NA>   \n",
       "\n",
       "                                                   Email  \\\n",
       "0                                                   <NA>   \n",
       "1                                                   <NA>   \n",
       "2                                                   <NA>   \n",
       "3                                                   <NA>   \n",
       "4      reception_kneesworthhouse@partnershipsincare.c...   \n",
       "...                                                  ...   \n",
       "19077                                               <NA>   \n",
       "19078                                               <NA>   \n",
       "19079                                               <NA>   \n",
       "19080                                               <NA>   \n",
       "19081                                               <NA>   \n",
       "\n",
       "                            Website           Fax  \n",
       "0                              <NA>  01932 253674  \n",
       "1                              <NA>          <NA>  \n",
       "2       http://www.nscphealth.co.uk          <NA>  \n",
       "3       www.bridgewaterhospital.com          <NA>  \n",
       "4      www.partnershipsincare.co.uk          <NA>  \n",
       "...                             ...           ...  \n",
       "19077                          <NA>          <NA>  \n",
       "19078                          <NA>          <NA>  \n",
       "19079                          <NA>          <NA>  \n",
       "19080                          <NA>          <NA>  \n",
       "19081                          <NA>          <NA>  \n",
       "\n",
       "[20311 rows x 22 columns]"
      ]
     },
     "execution_count": 10,
     "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": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OrganisationID</th>\n",
       "      <th>OrganisationCode</th>\n",
       "      <th>OrganisationType</th>\n",
       "      <th>SubType</th>\n",
       "      <th>Sector</th>\n",
       "      <th>OrganisationStatus</th>\n",
       "      <th>IsPimsManaged</th>\n",
       "      <th>OrganisationName</th>\n",
       "      <th>Address1</th>\n",
       "      <th>Address2</th>\n",
       "      <th>...</th>\n",
       "      <th>County</th>\n",
       "      <th>Postcode</th>\n",
       "      <th>Latitude</th>\n",
       "      <th>Longitude</th>\n",
       "      <th>ParentODSCode</th>\n",
       "      <th>ParentName</th>\n",
       "      <th>Phone</th>\n",
       "      <th>Email</th>\n",
       "      <th>Website</th>\n",
       "      <th>Fax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17970</td>\n",
       "      <td>NDA07</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Walton Community Hospital - Virgin Care Servic...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Rodney Road</td>\n",
       "      <td>...</td>\n",
       "      <td>Surrey</td>\n",
       "      <td>KT12 3LD</td>\n",
       "      <td>51.379997</td>\n",
       "      <td>-0.406042</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01932 414205</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>01932 253674</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17981</td>\n",
       "      <td>NDA18</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Woking Community Hospital (Virgin Care)</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Heathside Road</td>\n",
       "      <td>...</td>\n",
       "      <td>Surrey</td>\n",
       "      <td>GU22 7HS</td>\n",
       "      <td>51.315132</td>\n",
       "      <td>-0.556289</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01483 715911</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>18102</td>\n",
       "      <td>NLT02</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>NHS Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>Old Street</td>\n",
       "      <td>...</td>\n",
       "      <td>Avon</td>\n",
       "      <td>BS21 6BS</td>\n",
       "      <td>51.437195</td>\n",
       "      <td>-2.847193</td>\n",
       "      <td>NLT</td>\n",
       "      <td>North Somerset Community Partnership Community...</td>\n",
       "      <td>01275 872212</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>http://www.nscphealth.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>18138</td>\n",
       "      <td>NMP01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Bridgewater Hospital</td>\n",
       "      <td>120 Princess Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>Greater Manchester</td>\n",
       "      <td>M15 5AT</td>\n",
       "      <td>53.459743</td>\n",
       "      <td>-2.245469</td>\n",
       "      <td>NMP</td>\n",
       "      <td>Bridgewater Hospital (Manchester) Ltd</td>\n",
       "      <td>0161 2270000</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>www.bridgewaterhospital.com</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18142</td>\n",
       "      <td>NMV01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Kneesworth House</td>\n",
       "      <td>Old North Road</td>\n",
       "      <td>Bassingbourn</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>SG8 5JP</td>\n",
       "      <td>52.078121</td>\n",
       "      <td>-0.030604</td>\n",
       "      <td>NMV</td>\n",
       "      <td>Partnerships In Care Ltd</td>\n",
       "      <td>01763 255 700</td>\n",
       "      <td>reception_kneesworthhouse@partnershipsincare.c...</td>\n",
       "      <td>www.partnershipsincare.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20296</th>\n",
       "      <td>10617742</td>\n",
       "      <td>NBG7L</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Sunnybank Medical Centre</td>\n",
       "      <td>Town Gate</td>\n",
       "      <td>Wyke</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BD12 9NG</td>\n",
       "      <td>53.737923</td>\n",
       "      <td>-1.767982</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20297</th>\n",
       "      <td>10617743</td>\n",
       "      <td>NFH02</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Mendip Vale Medi...</td>\n",
       "      <td>Pudding Pie Lane</td>\n",
       "      <td>Langford</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS40 5EL</td>\n",
       "      <td>51.341579</td>\n",
       "      <td>-2.784808</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20298</th>\n",
       "      <td>10617744</td>\n",
       "      <td>NFH03</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Axbridge Medical...</td>\n",
       "      <td>Houlgate Way</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS26 2BJ</td>\n",
       "      <td>51.286285</td>\n",
       "      <td>-2.820388</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20299</th>\n",
       "      <td>10617746</td>\n",
       "      <td>NEMAM</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Lawton House Surgery</td>\n",
       "      <td>Bromley Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>CW12 1QG</td>\n",
       "      <td>53.163048</td>\n",
       "      <td>-2.205781</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20300</th>\n",
       "      <td>10617747</td>\n",
       "      <td>NFH04</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Wedmore Medical ...</td>\n",
       "      <td>St. Medard Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>BS28 4AY</td>\n",
       "      <td>51.227219</td>\n",
       "      <td>-2.816258</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20301 rows × 22 columns</p>\n",
       "</div>"
      ],
      "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                <NA>            Visible          False   \n",
       "20297                <NA>            Visible          False   \n",
       "20298                <NA>            Visible          False   \n",
       "20299                <NA>            Visible          False   \n",
       "20300                <NA>            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                                   <NA>     Rodney Road  ...   \n",
       "1                                   <NA>  Heathside Road  ...   \n",
       "2      North Somerset Community Hospital      Old Street  ...   \n",
       "3                      120 Princess Road            <NA>  ...   \n",
       "4                         Old North Road    Bassingbourn  ...   \n",
       "...                                  ...             ...  ...   \n",
       "20296                          Town Gate            Wyke  ...   \n",
       "20297                   Pudding Pie Lane        Langford  ...   \n",
       "20298                       Houlgate Way            <NA>  ...   \n",
       "20299                       Bromley Road            <NA>  ...   \n",
       "20300                    St. Medard Road            <NA>  ...   \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                    <NA>   SG8 5JP  52.078121  -0.030604            NMV   \n",
       "...                   ...       ...        ...        ...            ...   \n",
       "20296                <NA>  BD12 9NG  53.737923  -1.767982           <NA>   \n",
       "20297                <NA>  BS40 5EL  51.341579  -2.784808           <NA>   \n",
       "20298                <NA>  BS26 2BJ  51.286285  -2.820388           <NA>   \n",
       "20299                <NA>  CW12 1QG  53.163048  -2.205781           <NA>   \n",
       "20300                <NA>  BS28 4AY  51.227219  -2.816258           <NA>   \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                                               <NA>           <NA>   \n",
       "20297                                               <NA>           <NA>   \n",
       "20298                                               <NA>           <NA>   \n",
       "20299                                               <NA>           <NA>   \n",
       "20300                                               <NA>           <NA>   \n",
       "\n",
       "                                                   Email  \\\n",
       "0                                                   <NA>   \n",
       "1                                                   <NA>   \n",
       "2                                                   <NA>   \n",
       "3                                                   <NA>   \n",
       "4      reception_kneesworthhouse@partnershipsincare.c...   \n",
       "...                                                  ...   \n",
       "20296                                               <NA>   \n",
       "20297                                               <NA>   \n",
       "20298                                               <NA>   \n",
       "20299                                               <NA>   \n",
       "20300                                               <NA>   \n",
       "\n",
       "                            Website           Fax  \n",
       "0                              <NA>  01932 253674  \n",
       "1                              <NA>          <NA>  \n",
       "2       http://www.nscphealth.co.uk          <NA>  \n",
       "3       www.bridgewaterhospital.com          <NA>  \n",
       "4      www.partnershipsincare.co.uk          <NA>  \n",
       "...                             ...           ...  \n",
       "20296                          <NA>          <NA>  \n",
       "20297                          <NA>          <NA>  \n",
       "20298                          <NA>          <NA>  \n",
       "20299                          <NA>          <NA>  \n",
       "20300                          <NA>          <NA>  \n",
       "\n",
       "[20301 rows x 22 columns]"
      ]
     },
     "execution_count": 11,
     "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": 12,
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "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": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>OrganisationID</th>\n",
       "      <th>OrganisationCode</th>\n",
       "      <th>OrganisationType</th>\n",
       "      <th>SubType</th>\n",
       "      <th>Sector</th>\n",
       "      <th>OrganisationStatus</th>\n",
       "      <th>IsPimsManaged</th>\n",
       "      <th>OrganisationName</th>\n",
       "      <th>Address1</th>\n",
       "      <th>Address2</th>\n",
       "      <th>...</th>\n",
       "      <th>Latitude</th>\n",
       "      <th>Longitude</th>\n",
       "      <th>ParentODSCode</th>\n",
       "      <th>ParentName</th>\n",
       "      <th>Phone</th>\n",
       "      <th>Email</th>\n",
       "      <th>Website</th>\n",
       "      <th>Fax</th>\n",
       "      <th>northing</th>\n",
       "      <th>easting</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17970</td>\n",
       "      <td>NDA07</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Walton Community Hospital - Virgin Care Servic...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Rodney Road</td>\n",
       "      <td>...</td>\n",
       "      <td>51.379997</td>\n",
       "      <td>-0.406042</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01932 414205</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>01932 253674</td>\n",
       "      <td>165810.473974</td>\n",
       "      <td>510917.517174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17981</td>\n",
       "      <td>NDA18</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Woking Community Hospital (Virgin Care)</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Heathside Road</td>\n",
       "      <td>...</td>\n",
       "      <td>51.315132</td>\n",
       "      <td>-0.556289</td>\n",
       "      <td>NDA</td>\n",
       "      <td>Virgin Care Services Ltd</td>\n",
       "      <td>01483 715911</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>158381.343420</td>\n",
       "      <td>500604.836652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>18102</td>\n",
       "      <td>NLT02</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>NHS Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>North Somerset Community Hospital</td>\n",
       "      <td>Old Street</td>\n",
       "      <td>...</td>\n",
       "      <td>51.437195</td>\n",
       "      <td>-2.847193</td>\n",
       "      <td>NLT</td>\n",
       "      <td>North Somerset Community Partnership Community...</td>\n",
       "      <td>01275 872212</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>http://www.nscphealth.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>171305.775859</td>\n",
       "      <td>341119.365090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>18138</td>\n",
       "      <td>NMP01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Bridgewater Hospital</td>\n",
       "      <td>120 Princess Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>53.459743</td>\n",
       "      <td>-2.245469</td>\n",
       "      <td>NMP</td>\n",
       "      <td>Bridgewater Hospital (Manchester) Ltd</td>\n",
       "      <td>0161 2270000</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>www.bridgewaterhospital.com</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>395944.561405</td>\n",
       "      <td>383703.600293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18142</td>\n",
       "      <td>NMV01</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Hospital</td>\n",
       "      <td>Independent Sector</td>\n",
       "      <td>Visible</td>\n",
       "      <td>True</td>\n",
       "      <td>Kneesworth House</td>\n",
       "      <td>Old North Road</td>\n",
       "      <td>Bassingbourn</td>\n",
       "      <td>...</td>\n",
       "      <td>52.078121</td>\n",
       "      <td>-0.030604</td>\n",
       "      <td>NMV</td>\n",
       "      <td>Partnerships In Care Ltd</td>\n",
       "      <td>01763 255 700</td>\n",
       "      <td>reception_kneesworthhouse@partnershipsincare.c...</td>\n",
       "      <td>www.partnershipsincare.co.uk</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>244071.710013</td>\n",
       "      <td>534945.182860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20296</th>\n",
       "      <td>10617742</td>\n",
       "      <td>NBG7L</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Sunnybank Medical Centre</td>\n",
       "      <td>Town Gate</td>\n",
       "      <td>Wyke</td>\n",
       "      <td>...</td>\n",
       "      <td>53.737923</td>\n",
       "      <td>-1.767982</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>426887.040596</td>\n",
       "      <td>415302.519662</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20297</th>\n",
       "      <td>10617743</td>\n",
       "      <td>NFH02</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Mendip Vale Medi...</td>\n",
       "      <td>Pudding Pie Lane</td>\n",
       "      <td>Langford</td>\n",
       "      <td>...</td>\n",
       "      <td>51.341579</td>\n",
       "      <td>-2.784808</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>160625.127012</td>\n",
       "      <td>345341.262026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20298</th>\n",
       "      <td>10617744</td>\n",
       "      <td>NFH03</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Axbridge Medical...</td>\n",
       "      <td>Houlgate Way</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>51.286285</td>\n",
       "      <td>-2.820388</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>154503.665383</td>\n",
       "      <td>342794.591249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20299</th>\n",
       "      <td>10617746</td>\n",
       "      <td>NEMAM</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Lawton House Surgery</td>\n",
       "      <td>Bromley Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>53.163048</td>\n",
       "      <td>-2.205781</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>362932.494686</td>\n",
       "      <td>386243.408863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20300</th>\n",
       "      <td>10617747</td>\n",
       "      <td>NFH04</td>\n",
       "      <td>Clinic</td>\n",
       "      <td>UNKNOWN</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>Visible</td>\n",
       "      <td>False</td>\n",
       "      <td>Somerset Surgical Services At Wedmore Medical ...</td>\n",
       "      <td>St. Medard Road</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>...</td>\n",
       "      <td>51.227219</td>\n",
       "      <td>-2.816258</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>147932.429756</td>\n",
       "      <td>343009.593212</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20301 rows × 24 columns</p>\n",
       "</div>"
      ],
      "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                <NA>            Visible          False   \n",
       "20297                <NA>            Visible          False   \n",
       "20298                <NA>            Visible          False   \n",
       "20299                <NA>            Visible          False   \n",
       "20300                <NA>            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                                   <NA>     Rodney Road  ...  51.379997   \n",
       "1                                   <NA>  Heathside Road  ...  51.315132   \n",
       "2      North Somerset Community Hospital      Old Street  ...  51.437195   \n",
       "3                      120 Princess Road            <NA>  ...  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            <NA>  ...  51.286285   \n",
       "20299                       Bromley Road            <NA>  ...  53.163048   \n",
       "20300                    St. Medard Road            <NA>  ...  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           <NA>   \n",
       "20297  -2.784808           <NA>   \n",
       "20298  -2.820388           <NA>   \n",
       "20299  -2.205781           <NA>   \n",
       "20300  -2.816258           <NA>   \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                                               <NA>           <NA>   \n",
       "20297                                               <NA>           <NA>   \n",
       "20298                                               <NA>           <NA>   \n",
       "20299                                               <NA>           <NA>   \n",
       "20300                                               <NA>           <NA>   \n",
       "\n",
       "                                                   Email  \\\n",
       "0                                                   <NA>   \n",
       "1                                                   <NA>   \n",
       "2                                                   <NA>   \n",
       "3                                                   <NA>   \n",
       "4      reception_kneesworthhouse@partnershipsincare.c...   \n",
       "...                                                  ...   \n",
       "20296                                               <NA>   \n",
       "20297                                               <NA>   \n",
       "20298                                               <NA>   \n",
       "20299                                               <NA>   \n",
       "20300                                               <NA>   \n",
       "\n",
       "                            Website           Fax       northing  \\\n",
       "0                              <NA>  01932 253674  165810.473974   \n",
       "1                              <NA>          <NA>  158381.343420   \n",
       "2       http://www.nscphealth.co.uk          <NA>  171305.775859   \n",
       "3       www.bridgewaterhospital.com          <NA>  395944.561405   \n",
       "4      www.partnershipsincare.co.uk          <NA>  244071.710013   \n",
       "...                             ...           ...            ...   \n",
       "20296                          <NA>          <NA>  426887.040596   \n",
       "20297                          <NA>          <NA>  160625.127012   \n",
       "20298                          <NA>          <NA>  154503.665383   \n",
       "20299                          <NA>          <NA>  362932.494686   \n",
       "20300                          <NA>          <NA>  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": 14,
     "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": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {\n",
       "  /* Definition of color scheme common for light and dark mode */\n",
       "  --sklearn-color-text: black;\n",
       "  --sklearn-color-line: gray;\n",
       "  /* Definition of color scheme for unfitted estimators */\n",
       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
       "  --sklearn-color-unfitted-level-3: chocolate;\n",
       "  /* Definition of color scheme for fitted estimators */\n",
       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
       "  --sklearn-color-fitted-level-1: #d4ebff;\n",
       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
       "\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-icon: #696969;\n",
       "\n",
       "  @media (prefers-color-scheme: dark) {\n",
       "    /* Redefinition of color scheme for dark theme */\n",
       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-icon: #878787;\n",
       "  }\n",
       "}\n",
       "\n",
       "#sk-container-id-1 {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip: rect(1px 1px 1px 1px);\n",
       "  clip: rect(1px, 1px, 1px, 1px);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-dashed-wrapped {\n",
       "  border: 1px dashed var(--sklearn-color-line);\n",
       "  margin: 0 0.4em 0.5em 0.4em;\n",
       "  box-sizing: border-box;\n",
       "  padding-bottom: 0.4em;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-container {\n",
       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
       "     so we also need the `!important` here to be able to override the\n",
       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
       "  display: inline-block !important;\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-text-repr-fallback {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       "div.sk-parallel-item,\n",
       "div.sk-serial,\n",
       "div.sk-item {\n",
       "  /* draw centered vertical line to link estimators */\n",
       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
       "  background-size: 2px 100%;\n",
       "  background-repeat: no-repeat;\n",
       "  background-position: center center;\n",
       "}\n",
       "\n",
       "/* Parallel-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item::after {\n",
       "  content: \"\";\n",
       "  width: 100%;\n",
       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
       "  flex-grow: 1;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel {\n",
       "  display: flex;\n",
       "  align-items: stretch;\n",
       "  justify-content: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-serial {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "  align-items: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  padding-right: 1em;\n",
       "  padding-left: 1em;\n",
       "}\n",
       "\n",
       "\n",
       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
       "clickable and can be expanded/collapsed.\n",
       "- Pipeline and ColumnTransformer use this feature and define the default style\n",
       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
       "*/\n",
       "\n",
       "/* Pipeline and ColumnTransformer style (default) */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable {\n",
       "  /* Default theme specific background. It is overwritten whether we have a\n",
       "  specific estimator or a Pipeline/ColumnTransformer */\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "/* Toggleable label */\n",
       "#sk-container-id-1 label.sk-toggleable__label {\n",
       "  cursor: pointer;\n",
       "  display: block;\n",
       "  width: 100%;\n",
       "  margin-bottom: 0;\n",
       "  padding: 0.5em;\n",
       "  box-sizing: border-box;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
       "  /* Arrow on the left of the label */\n",
       "  content: \"▸\";\n",
       "  float: left;\n",
       "  margin-right: 0.25em;\n",
       "  color: var(--sklearn-color-icon);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content {\n",
       "  max-height: 0;\n",
       "  max-width: 0;\n",
       "  overflow: hidden;\n",
       "  text-align: left;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content pre {\n",
       "  margin: 0.2em;\n",
       "  border-radius: 0.25em;\n",
       "  color: var(--sklearn-color-text);\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
       "  /* Expand drop-down */\n",
       "  max-height: 200px;\n",
       "  max-width: 100%;\n",
       "  overflow: auto;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator-specific style */\n",
       "\n",
       "/* Colorize estimator box */\n",
       "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  /* The background is the default theme color */\n",
       "  color: var(--sklearn-color-text-on-default-background);\n",
       "}\n",
       "\n",
       "/* On hover, darken the color of the background */\n",
       "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "/* Label box, darken color on hover, fitted */\n",
       "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator label */\n",
       "\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  display: inline-block;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       "#sk-container-id-1 div.sk-estimator {\n",
       "  font-family: monospace;\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: 0.25em;\n",
       "  box-sizing: border-box;\n",
       "  margin-bottom: 0.5em;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       "#sk-container-id-1 div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
       "\n",
       "/* Common style for \"i\" and \"?\" */\n",
       "\n",
       ".sk-estimator-doc-link,\n",
       "a:link.sk-estimator-doc-link,\n",
       "a:visited.sk-estimator-doc-link {\n",
       "  float: right;\n",
       "  font-size: smaller;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1em;\n",
       "  height: 1em;\n",
       "  width: 1em;\n",
       "  text-decoration: none !important;\n",
       "  margin-left: 1ex;\n",
       "  /* unfitted */\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted,\n",
       "a:link.sk-estimator-doc-link.fitted,\n",
       "a:visited.sk-estimator-doc-link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "/* Span, style for the box shown on hovering the info icon */\n",
       ".sk-estimator-doc-link span {\n",
       "  display: none;\n",
       "  z-index: 9999;\n",
       "  position: relative;\n",
       "  font-weight: normal;\n",
       "  right: .2ex;\n",
       "  padding: .5ex;\n",
       "  margin: .5ex;\n",
       "  width: min-content;\n",
       "  min-width: 20ex;\n",
       "  max-width: 50ex;\n",
       "  color: var(--sklearn-color-text);\n",
       "  box-shadow: 2pt 2pt 4pt #999;\n",
       "  /* unfitted */\n",
       "  background: var(--sklearn-color-unfitted-level-0);\n",
       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted span {\n",
       "  /* fitted */\n",
       "  background: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link:hover span {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link {\n",
       "  float: right;\n",
       "  font-size: 1rem;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1rem;\n",
       "  height: 1rem;\n",
       "  width: 1rem;\n",
       "  text-decoration: none;\n",
       "  /* unfitted */\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "#sk-container-id-1 a.estimator_doc_link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>NearestNeighbors()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;NearestNeighbors<span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>NearestNeighbors()</pre></div> </div></div></div></div>"
      ],
      "text/plain": [
       "NearestNeighbors()"
      ]
     },
     "execution_count": 16,
     "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": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>long</th>\n",
       "      <th>infected</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>53.715828</td>\n",
       "      <td>-2.430079</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>53.664883</td>\n",
       "      <td>-2.425673</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>53.696766</td>\n",
       "      <td>-2.488940</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>53.696968</td>\n",
       "      <td>-2.488896</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>53.727806</td>\n",
       "      <td>-2.392959</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70875</th>\n",
       "      <td>51.662720</td>\n",
       "      <td>-2.926850</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70876</th>\n",
       "      <td>51.599346</td>\n",
       "      <td>-2.959175</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70877</th>\n",
       "      <td>51.543823</td>\n",
       "      <td>-2.822984</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70878</th>\n",
       "      <td>51.562538</td>\n",
       "      <td>-2.879491</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70879</th>\n",
       "      <td>51.628746</td>\n",
       "      <td>-2.837151</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>70880 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             lat      long infected\n",
       "0      53.715828 -2.430079      1.0\n",
       "1      53.664883 -2.425673      1.0\n",
       "2      53.696766 -2.488940      1.0\n",
       "3      53.696968 -2.488896      1.0\n",
       "4      53.727806 -2.392959      1.0\n",
       "...          ...       ...      ...\n",
       "70875  51.662720 -2.926850      1.0\n",
       "70876  51.599346 -2.959175      1.0\n",
       "70877  51.543823 -2.822984      1.0\n",
       "70878  51.562538 -2.879491      1.0\n",
       "70879  51.628746 -2.837151      1.0\n",
       "\n",
       "[70880 rows x 3 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "infected_filter = df['infected']==1.0\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": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>long</th>\n",
       "      <th>infected</th>\n",
       "      <th>northing</th>\n",
       "      <th>easting</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1346586</th>\n",
       "      <td>53.715828</td>\n",
       "      <td>-2.430079</td>\n",
       "      <td>1.0</td>\n",
       "      <td>424490.112088</td>\n",
       "      <td>371619.667512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1350932</th>\n",
       "      <td>53.664883</td>\n",
       "      <td>-2.425673</td>\n",
       "      <td>1.0</td>\n",
       "      <td>418820.846058</td>\n",
       "      <td>371876.457712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1352085</th>\n",
       "      <td>53.696766</td>\n",
       "      <td>-2.488940</td>\n",
       "      <td>1.0</td>\n",
       "      <td>422394.870545</td>\n",
       "      <td>367720.997655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1352799</th>\n",
       "      <td>53.696968</td>\n",
       "      <td>-2.488896</td>\n",
       "      <td>1.0</td>\n",
       "      <td>422416.913323</td>\n",
       "      <td>367723.982001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1357529</th>\n",
       "      <td>53.727806</td>\n",
       "      <td>-2.392959</td>\n",
       "      <td>1.0</td>\n",
       "      <td>425808.233176</td>\n",
       "      <td>374076.541266</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58459189</th>\n",
       "      <td>51.662720</td>\n",
       "      <td>-2.926850</td>\n",
       "      <td>1.0</td>\n",
       "      <td>196451.737635</td>\n",
       "      <td>335900.977614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58459551</th>\n",
       "      <td>51.599346</td>\n",
       "      <td>-2.959175</td>\n",
       "      <td>1.0</td>\n",
       "      <td>189433.231857</td>\n",
       "      <td>333572.971111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58461935</th>\n",
       "      <td>51.543823</td>\n",
       "      <td>-2.822984</td>\n",
       "      <td>1.0</td>\n",
       "      <td>183144.006910</td>\n",
       "      <td>342935.102589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58464082</th>\n",
       "      <td>51.562538</td>\n",
       "      <td>-2.879491</td>\n",
       "      <td>1.0</td>\n",
       "      <td>185270.694643</td>\n",
       "      <td>339042.064721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58464209</th>\n",
       "      <td>51.628746</td>\n",
       "      <td>-2.837151</td>\n",
       "      <td>1.0</td>\n",
       "      <td>192598.453599</td>\n",
       "      <td>342060.982494</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>70880 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                lat      long infected       northing        easting\n",
       "1346586   53.715828 -2.430079      1.0  424490.112088  371619.667512\n",
       "1350932   53.664883 -2.425673      1.0  418820.846058  371876.457712\n",
       "1352085   53.696766 -2.488940      1.0  422394.870545  367720.997655\n",
       "1352799   53.696968 -2.488896      1.0  422416.913323  367723.982001\n",
       "1357529   53.727806 -2.392959      1.0  425808.233176  374076.541266\n",
       "...             ...       ...      ...            ...            ...\n",
       "58459189  51.662720 -2.926850      1.0  196451.737635  335900.977614\n",
       "58459551  51.599346 -2.959175      1.0  189433.231857  333572.971111\n",
       "58461935  51.543823 -2.822984      1.0  183144.006910  342935.102589\n",
       "58464082  51.562538 -2.879491      1.0  185270.694643  339042.064721\n",
       "58464209  51.628746 -2.837151      1.0  192598.453599  342060.982494\n",
       "\n",
       "[70880 rows x 5 columns]"
      ]
     },
     "execution_count": 23,
     "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": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>long</th>\n",
       "      <th>infected</th>\n",
       "      <th>northing</th>\n",
       "      <th>easting</th>\n",
       "      <th>distance</th>\n",
       "      <th>closest_clinic_hospital</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1346586</th>\n",
       "      <td>53.715828</td>\n",
       "      <td>-2.430079</td>\n",
       "      <td>1.0</td>\n",
       "      <td>424490.112088</td>\n",
       "      <td>371619.667512</td>\n",
       "      <td>2562.548828</td>\n",
       "      <td>18316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1350932</th>\n",
       "      <td>53.664883</td>\n",
       "      <td>-2.425673</td>\n",
       "      <td>1.0</td>\n",
       "      <td>418820.846058</td>\n",
       "      <td>371876.457712</td>\n",
       "      <td>2988.746826</td>\n",
       "      <td>12816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1352085</th>\n",
       "      <td>53.696766</td>\n",
       "      <td>-2.488940</td>\n",
       "      <td>1.0</td>\n",
       "      <td>422394.870545</td>\n",
       "      <td>367720.997655</td>\n",
       "      <td>1162.734009</td>\n",
       "      <td>7785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1352799</th>\n",
       "      <td>53.696968</td>\n",
       "      <td>-2.488896</td>\n",
       "      <td>1.0</td>\n",
       "      <td>422416.913323</td>\n",
       "      <td>367723.982001</td>\n",
       "      <td>1162.294800</td>\n",
       "      <td>7785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1357529</th>\n",
       "      <td>53.727806</td>\n",
       "      <td>-2.392959</td>\n",
       "      <td>1.0</td>\n",
       "      <td>425808.233176</td>\n",
       "      <td>374076.541266</td>\n",
       "      <td>1455.020386</td>\n",
       "      <td>4962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58459189</th>\n",
       "      <td>51.662720</td>\n",
       "      <td>-2.926850</td>\n",
       "      <td>1.0</td>\n",
       "      <td>196451.737635</td>\n",
       "      <td>335900.977614</td>\n",
       "      <td>8617.890625</td>\n",
       "      <td>10015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58459551</th>\n",
       "      <td>51.599346</td>\n",
       "      <td>-2.959175</td>\n",
       "      <td>1.0</td>\n",
       "      <td>189433.231857</td>\n",
       "      <td>333572.971111</td>\n",
       "      <td>1306.792847</td>\n",
       "      <td>10015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58461935</th>\n",
       "      <td>51.543823</td>\n",
       "      <td>-2.822984</td>\n",
       "      <td>1.0</td>\n",
       "      <td>183144.006910</td>\n",
       "      <td>342935.102589</td>\n",
       "      <td>7633.324219</td>\n",
       "      <td>3814</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58464082</th>\n",
       "      <td>51.562538</td>\n",
       "      <td>-2.879491</td>\n",
       "      <td>1.0</td>\n",
       "      <td>185270.694643</td>\n",
       "      <td>339042.064721</td>\n",
       "      <td>7071.187500</td>\n",
       "      <td>10015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58464209</th>\n",
       "      <td>51.628746</td>\n",
       "      <td>-2.837151</td>\n",
       "      <td>1.0</td>\n",
       "      <td>192598.453599</td>\n",
       "      <td>342060.982494</td>\n",
       "      <td>10222.502930</td>\n",
       "      <td>10015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>70880 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                lat      long infected       northing        easting  \\\n",
       "1346586   53.715828 -2.430079      1.0  424490.112088  371619.667512   \n",
       "1350932   53.664883 -2.425673      1.0  418820.846058  371876.457712   \n",
       "1352085   53.696766 -2.488940      1.0  422394.870545  367720.997655   \n",
       "1352799   53.696968 -2.488896      1.0  422416.913323  367723.982001   \n",
       "1357529   53.727806 -2.392959      1.0  425808.233176  374076.541266   \n",
       "...             ...       ...      ...            ...            ...   \n",
       "58459189  51.662720 -2.926850      1.0  196451.737635  335900.977614   \n",
       "58459551  51.599346 -2.959175      1.0  189433.231857  333572.971111   \n",
       "58461935  51.543823 -2.822984      1.0  183144.006910  342935.102589   \n",
       "58464082  51.562538 -2.879491      1.0  185270.694643  339042.064721   \n",
       "58464209  51.628746 -2.837151      1.0  192598.453599  342060.982494   \n",
       "\n",
       "              distance  closest_clinic_hospital  \n",
       "1346586    2562.548828                    18316  \n",
       "1350932    2988.746826                    12816  \n",
       "1352085    1162.734009                     7785  \n",
       "1352799    1162.294800                     7785  \n",
       "1357529    1455.020386                     4962  \n",
       "...                ...                      ...  \n",
       "58459189   8617.890625                    10015  \n",
       "58459551   1306.792847                    10015  \n",
       "58461935   7633.324219                     3814  \n",
       "58464082   7071.187500                    10015  \n",
       "58464209  10222.502930                    10015  \n",
       "\n",
       "[70880 rows x 7 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distances, indices = knn.kneighbors(infected_df[['northing', 'easting']])\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": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "lat                            53.715828\n",
       "long                           -2.430079\n",
       "infected                             1.0\n",
       "northing                   424490.112088\n",
       "easting                    371619.667512\n",
       "distance                     2562.548828\n",
       "closest_clinic_hospital            18316\n",
       "Name: 1346586, dtype: object"
      ]
     },
     "execution_count": 25,
     "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": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OrganisationID                                             9445963\n",
       "OrganisationCode                                             NPR0F\n",
       "OrganisationType                                            Clinic\n",
       "SubType                                                    UNKNOWN\n",
       "Sector                                                        None\n",
       "OrganisationStatus                                         Visible\n",
       "IsPimsManaged                                                False\n",
       "OrganisationName      Community Dermatology Service - About Health\n",
       "Address1                                     The Innovation Centre\n",
       "Address2                                          1 Evolution Park\n",
       "Address3                                           Haslingden Road\n",
       "City                                                     Blackburn\n",
       "County                                                  Lancashire\n",
       "Postcode                                                   BB1 2FD\n",
       "Latitude                                                 53.733227\n",
       "Longitude                                                -2.455536\n",
       "ParentODSCode                                                 None\n",
       "ParentName                                                    None\n",
       "Phone                                                         None\n",
       "Email                                                         None\n",
       "Website                                                       None\n",
       "Fax                                                           None\n",
       "northing                                             426435.969251\n",
       "easting                                              369952.220236\n",
       "Name: 18316, dtype: object"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_med.iloc[18316] # 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": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>northing</th>\n",
       "      <th>easting</th>\n",
       "      <th>distance</th>\n",
       "      <th>closest_clinic_hospital</th>\n",
       "      <th>OrganisationID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>John Smith</td>\n",
       "      <td>462643.228292</td>\n",
       "      <td>363859.758057</td>\n",
       "      <td>7286.685059</td>\n",
       "      <td>4637</td>\n",
       "      <td>64351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Greg Brown</td>\n",
       "      <td>409324.103047</td>\n",
       "      <td>464084.508506</td>\n",
       "      <td>1561.915405</td>\n",
       "      <td>3886</td>\n",
       "      <td>62389</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "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": 30,
     "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": 31,
   "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": 32,
   "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": [
    "<div align=\"center\"><h2>Please Restart the Kernel</h2></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "...before moving to the next notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import IPython\n",
    "app = IPython.Application.instance()\n",
    "app.kernel.do_shutdown(True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://www.nvidia.com/dli\"><img src=\"images/DLI_Header.png\" alt=\"Header\" style=\"width: 400px;\"/></a>"
   ]
  }
 ],
 "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
}
