top of page
  • Rohan Dawar

COVID-19: Animated Bar Charts, Canadian Provinces & Territories

Building on the framework code of my COVID-19 Autodoc, I wrote a script to transform the Health Canada Covid-19 data into Flourish readable data to produce some bar chart animations. Specifically for Active Number of Cases and Rate of Active Cases in Canadian provinces & territories:

Script:

import pandas as pd
import requests, io

url = 'https://health-infobase.canada.ca/src/data/covidLive/covid19-download.csv'

def grab_df(csvurl):
	r = requests.get(csvurl)
	csv = r.content
	return pd.read_csv(io.StringIO(csv.decode('utf-8')))

def heatmapped(df, metric, remove_from):
    df['date'] = pd.to_datetime(df['date'])
    df = df.groupby(['prname','date'])[[metric]].sum().reset_index().pivot("prname", "date", metric).fillna(0)
    if remove_from:
    	return df.drop(labels=remove_from, axis=0)
    else:
    	return df

df = grab_df(url)
remove_from = ['Canada','Repatriated travellers']
hm_df = heatmapped(df, 'rateactive', remove_from)
hm_df.to_csv('rateactive.csv')
66 views0 comments

Commentaires


bottom of page