In [277]:
import pandas as pd
import geopandas as gpd
#Visual
import seaborn as sns
import matplotlib.pyplot as plt
import folium
#Etc
import numpy as np
import os
import sys

Get Datasets

In [278]:
covidLocation = pd.read_csv('data/c19_location.csv')
/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py:2718: DtypeWarning: Columns (24,30,34,136) have mixed types.Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)
In [279]:
def dataDefine(dataset, datasetName):
    print("Dataset : " + datasetName)
    print("Dimension : " + str(dataset.shape))
    if len(dataset.columns) > 10:
        print("Columns : " + ', '.join(dataset.columns[:10]) + ', Etc')
    else:
        print("Columns : " + ', '.join(dataset.columns))
In [280]:
dataDefine(covidLocation, "CovidLocations")
Dataset : CovidLocations
Dimension : (217, 42)
Columns : Location, Address, Latitude, Longitude, Dates, Date_1, Time_start_1, Time_end_1, Date_2, Time_start_2, Etc

Covid Safety

In [285]:
covidLocation = covidLocation[covidLocation['Latitude'].notna()]

covidLocation.head()
Out[285]:
Location Address Latitude Longitude Dates Date_1 Time_start_1 Time_end_1 Date_2 Time_start_2 Time_end_2 Date_3 Time_start_3 Time_end_3 Date_4 Time_start_4 Time_end_4 Date_5 Time_start_5 Time_end_5 Date_6 Time_start_6 Time_end_6 Date_7 Time_start_7 Time_end_7 Date_8 Time_start_8 Time_end_8 Date_9 Time_start_9 Time_end_9 Date_10 Date_11 Date_12 Date_13 Date_14 Date_15 Action Status Date_Status_Current Date_Status_Expired
0 Adamstown: St Pius X High School Park Ave, Adamstown NSW 2289 -32.936923 151.714893 Monday 3 August 3-Aug NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Monitor for symptoms Expired 3-Aug 18-Aug
1 Albion Park: C1 Speed Indoor Karting 176-178 Princes Highway, Hargraves Ave, Albion... -34.561620 150.795619 6pm to 7pm on Saturday 11 July 11-Jul 18:00 19:00 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Monitor for symptoms Expired 11-Jul 26-Jul
2 Albion Park: McDonalds 251 Princes Hwy, Albion Park NSW 2527 -34.567215 150.803027 2pm to 2:30pm on Wednesday 15 July 15-Jul 14:00 14:30 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Monitor for symptoms Expired 15-Jul 30-Jul
3 Ashfield: New Shanghai Night restaurant 267c Liverpool Rd, Ashfield NSW 2131 -33.888329 151.124402 6:30pm to 8pm on Friday 4 September 4-Sep 18:30 20:00 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Self-isolate and get tested immediately Expired 4-Sep 19-Sep
4 Ashfield: The Crocodile Farm Hotel 262 Liverpool Rd, Ashfield NSW 2131 -33.888420 151.123999 5:30pm to 6:30pm on Friday 4 September 4-Sep 17:30 18:30 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Self-isolate and get tested immediately Expired 4-Sep 19-Sep
In [286]:
sydneyMap = folium.Map(location=[-33.862435, 151.100002], zoom_start= 11)
for i in range(covidLocation.shape[0]):
    if str(covidLocation.iloc[i]['Latitude']) != 'nan' and str(covidLocation.iloc[i]['Longitude']) != 'nan':
        folium.Marker(
            location=[covidLocation.iloc[i]['Latitude'], covidLocation.iloc[i]['Longitude']],
            popup= covidLocation.iloc[i]['Location'] + ', ' + covidLocation.iloc[i]['Dates'],
            icon=folium.Icon(color="red")
        ).add_to(sydneyMap)
In [287]:
sydneyMap
Out[287]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [288]:
from folium.plugins import HeatMap

sydneyMap_HeatMap = folium.Map(location=[-33.862435, 151.100002], zoom_start= 11)

heat_data = []
for i in range(covidLocation.shape[0]):
    if str(covidLocation.iloc[i]['Latitude']) != 'nan' and str(covidLocation.iloc[i]['Longitude']) != 'nan':
        heat_data.append([covidLocation.iloc[i]['Latitude'], covidLocation.iloc[i]['Longitude']])

HeatMap(heat_data, radius=15).add_to(sydneyMap_HeatMap)
Out[288]:
<folium.plugins.heat_map.HeatMap at 0x7f7791b59ed0>
In [289]:
sydneyMap_HeatMap
Out[289]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [290]:
postcodeSuburbData = pd.read_csv('data/postcodeSuburb.csv')
def getSuburb(postcode):
    try:
        postcode = int(postcode)
        return postcodeSuburbData.iloc[postcodeSuburbData.index[postcodeSuburbData['postcode']==postcode].tolist()]['suburb'].unique()
    except Exception:
        return 'NONE'
getSuburb(2077)
Out[290]:
array(['ASQUITH', 'HORNSBY', 'HORNSBY HEIGHTS', 'WAITARA'], dtype=object)
In [291]:
#Make Suburb Dataset
# Sample : Hume Hwy & Camden Valley Way, Casula NSW 2170
#string = 'Hume Hwy & Camden Valley Way, Casula NSW 2170'
#string = string.split(',')
#print(string)

covidLocation['Suburb'] = ''
covidLocation['postCode'] = ''
for i in range(covidLocation.shape[0]):
    try:
        string = list(list(covidLocation.iloc[i]['Address'].split(','))[-1].split(' '))
        string = ' '.join(string[:string.index('NSW')])
        if string == '':
            string = list(list(covidLocation.iloc[i]['Address'].split(','))[-1].split(' '))[0]
        if string == '':
            raise Exception()
        post = list(covidLocation.iloc[i]['Address'].split(' '))[-1]
        covidLocation.loc[i, 'Suburb'] = string
        covidLocation.loc[i, 'postCode'] = post
    except Exception:
        pass
In [292]:
covidSuburbData = pd.DataFrame(columns=['nsw_loca_2', 'PostCode', 'Count'])

counts = covidLocation['Suburb'].value_counts()

for suburb in covidLocation['Suburb'].unique():
    for sub in getSuburb(covidLocation.loc[covidLocation['Suburb'] == suburb].iloc[0]['postCode']):
        covidSuburbData = covidSuburbData.append({
            'nsw_loca_2': sub,
            'PostCode': covidLocation.loc[covidLocation['Suburb'] == suburb].iloc[0]['postCode'],
            'Count': counts[suburb]
        }, ignore_index=True)
    
covidSuburbData.drop(covidSuburbData.index[[8]], inplace=True)
covidSuburbData.head()
Out[292]:
nsw_loca_2 PostCode Count
0 ADAMSTOWN 2289 1
1 ADAMSTOWN HEIGHTS 2289 1
2 GARDEN SUBURB 2289 1
3 HIGHFIELDS 2289 1
4 KOTARA 2289 1
In [293]:
geoData = gpd.read_file('data/suburb-10-nsw.geojson')
geoData = geoData[['nsw_loca_2','geometry']]
print(geoData.shape)
geoData.head()
(4572, 2)
Out[293]:
nsw_loca_2 geometry
0 CROYDON PARK POLYGON ((151.11700 -33.89152, 151.11635 -33.8...
1 MAYFIELD WEST POLYGON ((151.73345 -32.87974, 151.73255 -32.8...
2 CAMPSIE POLYGON ((151.11002 -33.90297, 151.11062 -33.9...
3 WALLACETOWN POLYGON ((147.48238 -34.96891, 147.50777 -34.9...
4 CANTERBURY POLYGON ((151.12351 -33.90672, 151.12596 -33.9...
In [294]:
covidSuburbData = geoData.merge(covidSuburbData, on='nsw_loca_2')
print(covidSuburbData.shape)
covidSuburbData.head()
(523, 4)
Out[294]:
nsw_loca_2 geometry PostCode Count
0 CANTERBURY POLYGON ((151.12351 -33.90672, 151.12596 -33.9... 2193 3
1 CONCORD POLYGON ((151.10366 -33.84280, 151.10457 -33.8... 2137 2
2 CONCORD POLYGON ((151.10366 -33.84280, 151.10457 -33.8... 2137 1
3 WOLLSTONECRAFT POLYGON ((151.20334 -33.83116, 151.20354 -33.8... 2065 1
4 WOLLSTONECRAFT POLYGON ((151.20334 -33.83116, 151.20354 -33.8... 2065 1
In [295]:
sydney_suburb_HeatMap = folium.Map(location = [-33.862435, 151.100002], zoom_start=12)

sydney_suburb_HeatMap.choropleth(geo_data=covidSuburbData,        
             data=covidSuburbData,
             name='choroleth',
             columns=['nsw_loca_2','Count'], 
             key_on='feature.properties.nsw_loca_2', 
             fill_color='YlOrRd',
             fill_opacity=0.2, 
             line_opacity=0.2,
             legend_name='Covid Heat Signature',     
             highlight=True
                 )
/usr/local/lib/python3.7/dist-packages/folium/folium.py:426: FutureWarning: The choropleth  method has been deprecated. Instead use the new Choropleth class, which has the same arguments. See the example notebook 'GeoJSON_and_choropleth' for how to do this.
  FutureWarning
In [296]:
sydney_suburb_HeatMap
Out[296]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [299]:
plt.figure(figsize=(20, 6))
plt.bar(covidSuburbData[covidSuburbData['Count'] > 3]['nsw_loca_2'], covidSuburbData[covidSuburbData['Count'] > 3]['Count'])
plt.xticks(rotation=45)
Out[299]:
([0,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10,
  11,
  12,
  13,
  14,
  15,
  16,
  17,
  18,
  19,
  20,
  21,
  22,
  23,
  24,
  25,
  26,
  27,
  28,
  29,
  30,
  31],
 <a list of 32 Text major ticklabel objects>)
In [297]: