9 from scipy
.stats
import gmean
14 import matplotlib
as mpl
15 import matplotlib
.pyplot
as plt
17 # # %matplotlib inline
21 connection_string
= 'postgresql://covid:3NbjJTkT63@localhost/covid'
25 engine
= sqlalchemy
.create_engine(connection_string
)
29 qstr
= '''select uk_data.date
30 , uk_data.new_cases, uk_data_7.new_cases as new_cases_7
31 , uk_data.new_deaths, uk_data_7.new_deaths as new_deaths_7
32 from uk_data left outer join uk_data_7 using (date)
33 order by uk_data.date'''
34 uk_data
= pd
.read_sql_query(qstr
, engine
,
36 parse_dates
= ['date'])
39 ax
= uk_data
.loc
['2020-03-10':, ['new_cases', 'new_cases_7']].plot(
40 style
={'new_cases': "#e4e4e4",
44 title
="New cases and new deaths")
46 # ax.set_title('Fraction of tests with positive results')
47 ax
.legend(['New cases', 'New cases, 7 day moving average'], loc
='upper left')
48 ax
.set_ylabel('New cases')
51 ax2
= uk_data
.loc
['2020-03-10':, ['new_deaths','new_deaths_7']].plot(
53 secondary_y
=['new_deaths', 'new_deaths_7'],
54 style
={'new_deaths': "#ffe4e4",
57 ax2
.legend(['New deaths', 'New deaths, 7 day moving average'], loc
='best')
58 ax2
.set_ylabel('New cases')
59 plt
.savefig('cases_and_deaths.png')
63 ax
= uk_data
.iloc
[-60:][['new_cases', 'new_cases_7']].plot(
64 style
={'new_cases': "#e4e4e4",
68 title
="New cases and new deaths")
70 # ax.set_title('Fraction of tests with positive results')
71 ax
.legend(['New cases', 'New cases, 7 day moving average'], loc
='upper left')
72 ax
.set_ylabel('New cases')
76 ax2
= uk_data
.iloc
[-60:][['new_deaths','new_deaths_7']].plot(
78 secondary_y
=['new_deaths', 'new_deaths_7'],
79 style
={'new_deaths': "#ffe4e4",
82 ax2
.legend(['New deaths', 'New deaths, 7 day moving average'], loc
='best')
83 ax2
.set_ylabel('New cases')
84 plt
.savefig('cases_and_deaths_last_60_days.png')