Importing and preparing the data

We will be looking at data from the following countries:

  • Italy
  • Austria
  • Germany
  • Belgium
  • France
  • United Kingdom

We begin by importing the data, and adding calculating some new features so that we can compare the data from different countries. For example we calculate 'confirmed cases per 100k population', 'deaths per 100k' and 'new cases' since these are not initially in the dataset.

from covid19dh import covid19
import altair as alt
import datetime

countries = ["Italy", 
             "Austria",
             "Germany",
             "Belgium",
             "France",
             "United Kingdom",
             "Switzerland"
            ]

yesterday = datetime.date.today() - datetime.timedelta(days=1)

x, src = covid19(countries, raw=True, verbose=False, end=yesterday, cache=False)

x_small = x.loc[:, ['administrative_area_level_1', 'date', 'vaccines', 'confirmed','tests', 'recovered', 'deaths', 'population']]
x_small.rename(columns={'administrative_area_level_1': 'id'}, inplace=True)

x_small['confirmed_per'] = 100000 * x_small['confirmed'] / x_small['population']
x_small['deaths_per'] = 100000 * x_small['deaths'] / x_small['population']
x_small['ratio'] = 100 * (x_small['deaths']) / (x_small['confirmed'])
x_small['tests_per'] = 100000 * (x_small['tests']) / (x_small['population'])
x_small['vaccines_per'] = x_small['vaccines'] / x_small['population']

x_small['new_cases']=x_small.groupby('id').confirmed.diff().fillna(0)
x_small['new_cases_per']=x_small.groupby('id').confirmed_per.diff().fillna(0)

Here is a random sample of 5 rows from the dataset.

x_small.tail()
id date vaccines confirmed tests recovered deaths population confirmed_per deaths_per ratio tests_per vaccines_per new_cases new_cases_per
53866 Italy 2021-09-13 81189832.0 4609205.0 87573881.0 4353346.0 129955.0 60421760 7628.385866 215.079799 2.819467 144937.653256 1.343718 2792.0 4.620852
53867 Italy 2021-09-14 81427413.0 4613214.0 87892474.0 4360847.0 130027.0 60421760 7635.020893 215.198961 2.818577 145464.935149 1.347650 4009.0 6.635027
53868 Italy 2021-09-15 81649249.0 4618040.0 88210140.0 4369453.0 130100.0 60421760 7643.008082 215.319779 2.817212 145990.682827 1.351322 4826.0 7.987189
53869 Italy 2021-09-16 81861700.0 4623155.0 88516407.0 4376646.0 130167.0 60421760 7651.473575 215.430666 2.815545 146497.564785 1.354838 5115.0 8.465493
53870 Italy 2021-09-17 82070636.0 4627699.0 88800986.0 4383195.0 130233.0 60421760 7658.994045 215.539898 2.814206 146968.552389 1.358296 4544.0 7.520469

Plotting the data

We will first look at the total numbers of cases and deaths in each country, before moving on to cases and deaths per 100k population.

In each of the charts below, you can click on the legend to filter the lines shown

Total cases per 100,000

leg_selection = alt.selection_multi(fields=['id'], bind='legend')

alt.Chart(x_small).mark_line().encode(
    x=alt.X("yearmonthdate(date):T", axis=alt.Axis(title='Date')),
    y=alt.Y("confirmed_per:Q", axis=alt.Axis(title='Confirmed per 100k')),
    tooltip=['id', 'confirmed_per'],
    color=alt.Color('id', legend=alt.Legend(title="Countries")),
    opacity=alt.condition(leg_selection, alt.value(1), alt.value(0.2))
).add_selection(leg_selection).properties(title='Total number of cases per 100,000 population for selected European Countries', width=600).interactive()