Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2020 15:57
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
scraper for count of Swiss coronavirus confirmed cases
# pip3 install pandas matplotlib
import pandas as pd
from matplotlib import pyplot as plt
# this gets the worldwide confirmed cases from JHU
url = ''
# read/download csv
df = pd.read_csv(url)
# filter on Swiss data
df = df[df['Country/Region'] == 'Switzerland']
# remove unnecessary columns
df.drop(['Province/State', 'Lat','Long'], axis=1, inplace=True)
# unpivot aka "melt"
df = df.melt(id_vars=['Country/Region'], var_name='date', value_name='confirmed_cases')
# rename column
df.rename(columns={'Country/Region': 'country'}, inplace=True)
# convert date column to date-type = pd.to_datetime(
# not needed
#df = df.set_index(
# write to plot, save as file
plt.plot(, df.confirmed_cases, '-')
_ = plt.xticks(rotation=45)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment