The poor rabbit chased by Python and Anaconda :p

0%

Australia covid 19 Track

1
2
3
4
5
6
7
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.ticker as ticker
import calendar
%matplotlib inline

create a past data base

daily diagnosis table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def create_daily_case(readfromfile = False):
'''
create a data table from previous day file, or from oldest file
'''

if readfromfile == True:
with open('newest_daily.csv') as f:
olddailydf = pd.read_csv(f,header = 0)
else:
with open('ausvirus.csv') as f:
datadf = pd.read_csv(f,header = 0)
newdf = datadf.transpose().iloc[0:24,]
drange = pd.date_range('20200301','20200324',freq='D')
newdf.index = drange[::-1]
columnlist = ['NSW','VIC','QLD','WA','SA','TAS','ACT','NT']
newdf.columns = columnlist
newdf = newdf.fillna(0).astype(int)
newdf = newdf.iloc[1:,][::-1]
newdf['AUS'] = newdf.sum(axis=1).values
optdf = newdf
return optdf
1
newdf = create_daily_case(readfromfile = False)
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
def plot_daily_new_cases(newdf):
'''
plot australia daily new coronavirus cases
'''

plotdf = newdf.reset_index().melt(id_vars = 'index')
sns.set(style='darkgrid', palette='deep', font='sans-serif', font_scale=2,
color_codes=True, rc={"lines.linewidth": 6,'lines.markersize': 14})
fig,ax = plt.subplots(figsize=(24,10))
ax = sns.lineplot(x='index',y='value',hue='variable',data=plotdf, marker='o', dashes=True)
ax.set(title="Australia Daily New Covid-19 Cases")
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.set_xlabel("Date",fontsize=30)
ax.set_ylabel("Number of Cases",fontsize=40)
ax.xaxis.set_tick_params(labelsize = 16,rotation=15)

item = plotdf.groupby('variable')
palette = sns.color_palette('deep').as_hex()

for i in range(newdf.shape[1]):
curdf = newdf.iloc[:,i].to_frame().reset_index().values
for x,y in curdf:
ax.text(x,y,f'{y:d}',color=palette[i])


plot_daily_new_cases(newdf)

png