CoCalc Public FilesVIS / tests.sagewsOpen in with one click!
Author: Hal Snyder
Views : 104
Description: Sample worksheet: display of IL COVID-19 testing data

COVID-19 Display IL Testing Time Series

%auto %default_mode python3
import pandas as pd import numpy as np
# use testing series collected by The Covid Tracking Project # https://covidtracking.com/api/ state = "IL" #url = f"https://covidtracking.com/api/states/daily.csv?state={state}" url = f"https://covidtracking.com/api/v1/states/{state}/daily.csv" url
'https://covidtracking.com/api/v1/states/IL/daily.csv'
# fetch state data from Covid Tracking Project # keep only a few columns df = pd.read_csv(url, parse_dates=['date', 'dateChecked'])[['date','positive','death','total']]
# use date as x-axis for displays so make it the index df.set_index('date', inplace=True) df.set_index(df.index.strftime('%m/%d'), inplace=True) df.sort_index(inplace=True)
df.head(2)
positive death total
date
03/04 4 NaN 155
03/05 5 NaN 197
df.tail()
positive death total
date
05/26 113195 4923.0 786794
05/27 114306 5083.0 803973
05/28 115833 5186.0 829966
05/29 117455 5270.0 851762
05/30 118917 5330.0 877105
df[-30:].plot(y=['positive','total'], kind="bar", figsize=[8, 5], rot=45, fontsize=7);
df['positive/total'] = df.loc[:,'positive']/df.loc[:,'total']
title = f"COVID-19 positive tests / total tests in {state}" df[-30:].plot(y=['positive/total'], kind="bar", figsize=[8, 5], rot=45, fontsize=7, title=title);
# just the confirmed (positives) title = f"COVID-19 cumulative confirmed cases in {state}" df[-30:].plot(y=['positive'], kind="bar", figsize=[8, 5], rot=45, fontsize=7, title=title);
df['new_cases_per_day'] = df['positive'].diff()
title = f"COVID-19 new cases reported each day in {state}" df[-30:].plot(y=['new_cases_per_day'], kind="bar", figsize=[8, 5], rot=45, fontsize=7, title=title);
df.tail()
positive death total positive/total new_cases_per_day
date
05/26 113195 4923.0 786794 0.143869 1178.0
05/27 114306 5083.0 803973 0.142176 1111.0
05/28 115833 5186.0 829966 0.139564 1527.0
05/29 117455 5270.0 851762 0.137897 1622.0
05/30 118917 5330.0 877105 0.135579 1462.0
# deaths title = f"COVID-19 deaths in {state}" df[-30:].plot(y=['death'], kind="bar", figsize=[8, 5], rot=45, fontsize=7, title=title);
df['deaths_each_day'] = df['death'].diff()
title = f"COVID-19 deaths each day in {state}" df[-30:].plot(y=['deaths_each_day'], kind="bar", figsize=[8, 5], rot=45, fontsize=7, title=title);