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
covidLocation = pd.read_csv('data/c19_location.csv')
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))
dataDefine(covidLocation, "CovidLocations")
covidLocation = covidLocation[covidLocation['Latitude'].notna()]
covidLocation.head()
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)
sydneyMap
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)
sydneyMap_HeatMap
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)
#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
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()
geoData = gpd.read_file('data/suburb-10-nsw.geojson')
geoData = geoData[['nsw_loca_2','geometry']]
print(geoData.shape)
geoData.head()
covidSuburbData = geoData.merge(covidSuburbData, on='nsw_loca_2')
print(covidSuburbData.shape)
covidSuburbData.head()
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
)
sydney_suburb_HeatMap
plt.figure(figsize=(20, 6))
plt.bar(covidSuburbData[covidSuburbData['Count'] > 3]['nsw_loca_2'], covidSuburbData[covidSuburbData['Count'] > 3]['Count'])
plt.xticks(rotation=45)