-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateDataLegacy.py
130 lines (88 loc) · 3.53 KB
/
UpdateDataLegacy.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
"""
Update Coronavirus data for Wisconsin and make standard plots
Script for downloading, parsing, plotting Covid data from Wisconsin.
"""
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import covid
#%% Update the data
# covid data by county
covid.update_covid_data_wi('state')
covid.update_covid_data_wi('county')
widata = covid.read_covid_data_wi('county')
state = covid.read_covid_data_wi('state')
# population data
datapath = '.\\data'
csv_file_pop = os.path.join(datapath, 'Population-Data-WI.csv')
# covid.download_pop_data_wi(csv_file_pop)
popdata = covid.read_pop_data_wi(csv_file_pop)
#%% Update Dashboard plots
plotpath = '.\\docs\\assets\\plotly'
# reduce and rename at state level
col_rename = {'POS_NEW': 'Cases', 'TEST_NEW': 'Tests', 'DTH_NEW': 'Deaths', 'HOSP_NEW': 'Hospitalizations'}
state = state.rename(columns=col_rename)
# Cases / Tests line plot
covid.plotly_casetest(sourcedata=state,
case_col='Cases',
test_col='Tests',
date_col='Date',
savefile=plotpath + '\\Cases-Tests-WI.html',
range_max=7000,
)
# Deaths / Hospitalizations line plot
covid.plotly_deadhosp(sourcedata=state,
hosp_col='Hospitalizations',
dead_col='Deaths',
date_col='Date',
savefile=plotpath + '\\Deaths-Hosp-WI.html',
)
# Map plots by importing other script
import UpdateGeo
# Regional plots by importing other script
import UpdateRegional
#%%
#%% Tract work - UWM and Marquette
# # covid data by census tract
# UWM = ['007300', '007400', '007800', '007500']
# Marquette = ['186400', '014600', '014700']
#%% Plot cases and deaths for the state
# use seaborn theme for plotting
# sns.set()
# covid.plot_tests_posrate(widata, 'WI')
# covid.plot_cases_deaths(widata, 'WI')
# covid.plot_cases_tests(widata, 'WI')
#%% Plot deaths, cases, tests
# WI and top 3 counties
# covid.plotDCT(widata, 'WI')
covid.plotDCT(widata, ['WI', 'Milwaukee', 'Dane', 'Brown'], per_capita=True, popdata=popdata)
#%% Plot by county
covid.plot_by_county(widata, popdata, 'POS_NEW', 9)
# covid.plot_by_county(widata, popdata, 'DTH_NEW', 6)
#%% Various groups of counties, cases and pos rate
# Current hot spots - sort by per-capita new cases
pivot = widata.pivot(index='Date', columns='NAME', values='POS_NEW')
avg = pivot.rolling(window=7, center=False).mean()
capita = covid.convert_per_capita(avg, popdata)
counties = capita.columns
last_value = capita.iloc[-1]
sort_order = last_value.sort_values(ascending=False)
hotspots = sort_order.index[0:8].insert(0,'WI')
covid.plot_cases_posrate(widata, hotspots, per_capita=True, popdata=popdata)
plt.suptitle('Hotspots')
# Sort counties by population
popcounties = popdata.sort_values(ascending=False).head(9).index
covid.plot_cases_posrate(widata, popcounties, per_capita=True, popdata=popdata)
# Milwaukee area
covid.plot_cases_posrate(widata, ['WI', 'Milwaukee', 'Waukesha', 'Kenosha', 'Racine', 'Washington'], per_capita=True, popdata=popdata)
plt.suptitle('Milwaukee area')
#%% Plot age distribution
# Note - this data is not present for counties. Only data broken out by
# county is deaths, cases, tests.
covid.plot_by_age(widata)
# Statement to compute new positives for all counties, before I realized
# the data wasn't there. Functions are still useful to learn.
# widata[new_cols] = widata.groupby('NAME')[cumul_cols].diff()