Table of Contents

Importing and Displaying CDC Vaccine Data

In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import math

# https://www.opendatanetwork.com/dataset/datahub.smcgov.org/dmz9-a27g
# df_clinic = pd.read_json('https://datahub.smcgov.org/resource/dmz9-a27g.json', orient='columns')

# https://dev.socrata.com/foundry/data.cdc.gov/pvgy-252u
# df_mal = pd.read_json('https://data.cdc.gov/resource/pvgy-252u.json', orient='columns')

# https://www.opendatanetwork.com/dataset/data.cityofnewyork.us/w9ei-idxz
df_fluvac = pd.read_json('https://data.cityofnewyork.us/resource/w9ei-idxz.json', orient='columns')

clinic_data = {
    'X Coordinate' : [],
    'Y Coordinate' : [],
    'Phone' : [],
    'Address' : [],
    'Name' : [],
    'ZIP Code' : [],
}

# Explanation for how to covert lon/lat to mercator coordinates
# https://gis.stackexchange.com/questions/156035/calculating-mercator-coordinates-from-lat-lon/156046
def merc(lat, lon):
    r_major = 6378137.000
    x = r_major * math.radians(lon)
    scale = x/lon
    y = 180.0/math.pi * math.log(math.tan(math.pi/4.0 + lat * (math.pi/180.0)/2.0)) * scale
    return (x, y)

# Loop goes through all given vaccine clinics and parses the following data points into a dictionary
for i in range(len(df_fluvac['latitude'])):
    
    # Takes given coordinates and coverts to mercator for OSM plotting
    cord = merc(df_fluvac['latitude'][i], df_fluvac['longitude'][i])
    
    # Clinic name
    clinic_data['Name'].append(df_fluvac['facility_name'][i])
    
    # Clinic phone number, address and ZIP code
    clinic_data['Phone'].append(df_fluvac['phone'][i])
    clinic_data['Address'].append(df_fluvac['address'][i])
    clinic_data['ZIP Code'].append(df_fluvac['zip_code'][i])
    
    # Coordinates for the given clinic
    clinic_data['X Coordinate'].append(cord[0])
    clinic_data['Y Coordinate'].append(cord[1])
    
# Stores dataset created above in a dataframe for easy interpretation
dataset = pd.DataFrame.from_dict(clinic_data)
dataset
Out[2]:
X Coordinate Y Coordinate Phone Address Name ZIP Code
0 -8.228747e+06 4.978229e+06 (718) 728-9100 28-04 31st Street Newtown Pharmacy 11102
1 -8.224083e+06 4.974014e+06 (800) 358-9950 84-20 Broadway Walgreens Drug Store 11373
2 -8.232768e+06 4.954047e+06 718-616-4594 1601 AVENUE S Homecrest Clinic 11229
3 -8.235533e+06 4.954290e+06 (718) 513-3322 260 Kings Highway Medcare Health Inc. 11223
4 -8.234034e+06 4.977024e+06 212-223-1765 949 3RD AVE Duane Reade 10022
5 -8.219533e+06 4.965528e+06 718-659-9621 10309 LIBERTY AVE Duane Reade 11417
6 -8.234322e+06 4.960363e+06 (718) 856-2976 1001 Church Avenue Drugs Care Pharmacy 11218
7 -8.235353e+06 4.976680e+06 212-730-4914 22 W 48TH ST Duane Reade 10036
8 -8.225623e+06 4.970008e+06 (718) 386-0989 66-26 metropolitan Avenue Kmart Pharamcy 11379
9 -8.238659e+06 4.955167e+06 (800) 358-9950 1511 86th Street Walgreens Drug Store 11228
10 -8.230988e+06 4.988955e+06 (212) 491-1661 600 West 168th Street Washington Hts HC *Special Event* 10032
11 -8.235834e+06 4.979878e+06 212-580-0497 253 W 72ND ST Duane Reade 10023
12 -8.229405e+06 4.977201e+06 (718) 728-9080 32-14 31st Street Rite Aid Pharmacy 11106
13 -8.236162e+06 4.971971e+06 (212) 388-9348 81 1st Avenue Rite Aid Pharmacy 10003
14 -8.216352e+06 4.980973e+06 (718) 767-6000 153-65 Cross Island Pkwy Rite Aid Pharmacy 11357
15 -8.232878e+06 4.977908e+06 (212) 628-1900 1292 1st Avenue Tower Chemists 10021
16 -8.232744e+06 4.954945e+06 (718) 998-3377 1720 Kings Highway Rite Aid Pharmacy 11229
17 -8.239093e+06 4.969101e+06 212-425-8460 37 BROADWAY Duane Reade 10006
18 -8.232506e+06 4.972489e+06 (718) 389-2403 859 MANHATTAN AVE. CVS 11222
19 -8.231611e+06 4.956659e+06 (718) 258-1812 2577 Nostrand Avenue Rite Aid Pharmacy 11210
20 -8.237916e+06 4.974045e+06 (212) 366-4085 81 EIGHTH AVE. CVS 10011
21 -8.215354e+06 4.968705e+06 (800) 358-9950 159-34 Jamaica Avenue Walgreens Drug Store 11432
22 -8.220357e+06 4.989102e+06 (718) 829-6808 2748 East Tremont Avenue Rite Aid Pharmacy 10461
23 -8.229259e+06 4.963234e+06 (800) 358-9950 1134 East New York Avenue Walgreens Drug Store 11212
24 -8.232371e+06 4.952098e+06 (718) 648-6971 1710 Avenue Y Stop and Shop Pharmacy 11235
25 -8.237415e+06 4.954173e+06 (718) 373-8185 2007 86th Street Rite Aid Pharmacy 11214
26 -8.222459e+06 4.972323e+06 (718) 997-6900 93-05 63rd Drive VNS Pharmacy (Neighboorhood Drug Store) 11374
27 -8.228798e+06 4.976566e+06 (718) 278-2100 32-87 Steinway Street Rite Aid Pharmacy 11103
28 -8.234996e+06 4.967496e+06 718 260 7835 100 NORTH PORTLAND AVENUE Cumberland Diagnostic and Treatment Center 11205
29 -8.232598e+06 4.979048e+06 (212) 327-4757 1535 2nd Avenue Rite Aid Pharmacy 10075
... ... ... ... ... ... ...
855 -8.231358e+06 4.981086e+06 212-423-2042 333 E 102ND ST Duane Reade 10029
856 -8.232511e+06 4.980220e+06 212-722-0014 1356 LEXINGTON AVE Duane Reade 10128
857 -8.237520e+06 4.974874e+06 646-486-7430 315 W 23RD ST Duane Reade 10011
858 -8.238810e+06 4.960115e+06 718-439-0614 5008 5TH AVE Duane Reade 11220
859 -8.218140e+06 4.987172e+06 (718) 792-9258 3590 East Tremont Avenue Rite Aid Pharmacy 10465
860 -8.234532e+06 4.976128e+06 (212) 758-2503 757 3RD AVE. CVS 10017
861 -8.225703e+06 4.986460e+06 (800) 358-9950 1041 Westchester Avenue Walgreens Drug Store 10459
862 -8.224213e+06 4.987087e+06 (718) 861-2359 1516 Westchester Avenue Rite Aid Pharmacy 10472
863 -8.221703e+06 4.986703e+06 (718) 430-9513 1998 Bruckner blvd Kmart Pharamcy 10473
864 -8.229487e+06 4.955497e+06 (800) 358-9950 2325 Flatbush Ave. Walgreens Drug Store 11234
865 -8.234693e+06 4.975224e+06 212-599-7492 300 E 39TH ST Duane Reade 10016
866 -8.228602e+06 4.976838e+06 718-932-6950 4002 BROADWAY Duane Reade 11103
867 -8.228454e+06 4.956649e+06 (718) 209-8121 2320 RALPH AVE. CVS 11234
868 -8.232636e+06 4.951704e+06 (781) 332-8345 1402 SHEEPSHEAD BAY ROAD CVS 11235
869 -8.230802e+06 4.961046e+06 (718) 940-1579 4102 Church Avenue Rite Aid Pharmacy 11203
870 -8.222911e+06 4.991059e+06 (917) 708-9700 2171 White Plains Rd Pelham Pharmacy 10462
871 -8.220072e+06 4.966718e+06 (718) 441-1120 102-30 Atlantic Avenue Rite Aid Pharmacy 11416
872 -8.250285e+06 4.948633e+06 (718) 987-9727 2690 HYLAN BOULEVARD CVS 10306
873 -8.221310e+06 4.990650e+06 (718) 239-7569 1916 WILLIAMSBRIDGE ROAD CVS 10461
874 -8.232271e+06 4.980219e+06 (212) 534-6000 1619 3rd Avenue Kings Third Avenue Pharmacy 10128
875 -8.236786e+06 4.967792e+06 (718) 834-9003 101 Clark Street Gristides Pharmacy 11201
876 -8.241333e+06 4.956225e+06 (718) 491-0442 9302 3rd Avenue Rite Aid Pharmacy 11209
877 -8.224834e+06 4.975490e+06 (718) 899-0200 81-25 37th Avenue Nueva Vida Pharmacy 11372
878 -8.228450e+06 4.994478e+06 (718) 432-3030 21B Knolls Crescent Rite Aid Pharmacy 10463
879 -8.222522e+06 4.973102e+06 (718) 760-6479 61-35 Junction Blvd Costco Pharmacy 11374
880 -8.213970e+06 4.969919e+06 (800) 358-9950 175-06 Hillside Avenue Walgreens Drug Store 11432
881 -8.255165e+06 4.957353e+06 718-616-4594 2040 FOREST AVENUE Mariner's Harbor Houses CHC 10303
882 -8.236596e+06 4.976443e+06 212-273-0889 625 8TH AVE Duane Reade 10018
883 -8.211336e+06 4.953361e+06 646-680-3000 29-15 FAR ROCKAWAY BOULEVARD Advantagecare Physicans Medical Office 11691
884 -8.228802e+06 4.962434e+06 (718) 345-6355 1154 Clarkson Avenue Rite Aid Pharmacy 11212

885 rows × 6 columns

Graphing CDC Vaccine Data

In [3]:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, output_notebook
from bokeh.models import HoverTool
from bokeh.tile_providers import get_provider, Vendors
from bokeh.io import show
output_notebook()

tile_provider = get_provider(Vendors.CARTODBPOSITRON)

source=ColumnDataSource(clinic_data)

# Determines size of map to create given the 
# most extreme longitude and latitude from all clinic locations
x_range=(min(clinic_data['X Coordinate']),max(clinic_data['X Coordinate']))
y_range=(min(clinic_data['Y Coordinate']),max(clinic_data['Y Coordinate']))

# Determines how to construct the map and tools for user interaction
plot = figure(title='Disease Map', 
              # Tools the user can control from right sidebar
              tools='pan,wheel_zoom', 
              # Range used to determine plot size
              x_range=x_range, y_range=y_range, 
              # Type of coordinates to plot
              x_axis_type="mercator", y_axis_type="mercator",
              # Size of the map
              width=600, height=600)

# Configure Open Street Maps to be our mapping provider
plot.add_tile(tile_provider)

# Plot circles at the coordinates for each given clinic
plot.circle(x="X Coordinate", y="Y Coordinate", size=5, fill_color="green", fill_alpha=0.8, source=source)

# When the cursor hovers over a given clinic, the name, phone number and address 
# will be taken from our dataframe and referenced in the plot.
plot.add_tools(HoverTool(tooltips=[
    ("", "@Name"),
    ("Phone", "@Phone"),
    ("Address", "@Address"),
]))

# Display map inside of this page
show(plot, notebook_handle=True)
Loading BokehJS ...
Out[3]:

<Bokeh Notebook handle for In[3]>

Determine Clinics Nearby with Given Zip Code

In [7]:
"""
Change this variable to any ZIP code within NYC to determine nearby clinics.
This will not work on a published page, the Jupyter Notebook server must be running
for code execution to occur.
"""
given_zip = 10016

# Dataset of all nearby clinics will be stored in this dictionary
nearby_clinics = {
    'Clinic Name' : [],
    'Address' : [],
}

# Parse all clinics displayed in the Bokeh OSM plot above to determine which ones
# are nearby according to ZIP code
for i in range(len(clinic_data['ZIP Code'])):
    if clinic_data['ZIP Code'][i] == given_zip:
        
        # Store dataframe clinic data in nearby clinic dictionary if nearby
        nearby_clinics["Clinic Name"].append(clinic_data['Name'][i])
        nearby_clinics["Address"].append(clinic_data['Address'][i])

# Produce new dataframe for our nearby clinics
dataset = pd.DataFrame.from_dict(nearby_clinics)
dataset
Out[7]:
Clinic Name Address
0 Duane Reade 260 MADISON AVE
1 Duane Reade 465 2ND AVE
2 NYU Hospital Center 530 1st Avenue
3 Rite Aid Pharmacy 542 Second Avenue
4 Bellevue Hospital 462 1 AVENUE
5 Rite Aid Pharmacy 524 Second Avenue
6 Duane Reade 401 PARK AVE S
7 Duane Reade 4 PARK AVE
8 Duane Reade 585 2ND AVE
9 CVS 222 EAST 34TH STREET
10 Duane Reade 155 E 34TH ST
11 Walgreens Drug Store 545 3rd Avenue
12 Duane Reade 300 E 39TH ST