Importing and preparing the data

We will be looking at data from the following countries:

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

We begin by importing the data, and adding 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. This data is collected and preprocessed in this file.

import altair as alt
import pandas as pd

x_small_url = "https://raw.githubusercontent.com/idjotherwise/nlp-otherwise/master/data_sets/european_covid.csv"

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

x_small = pd.read_csv(x_small_url)
x_small.sample(5)
id date vaccines confirmed tests recovered deaths population confirmed_per deaths_per ratio tests_per vaccines_per new_cases new_cases_per
2725 Germany 2020-09-29 NaN 291204.0 NaN 281353.0 9851.0 82905782.0 351.246913 11.882163 3.382852 NaN NaN 2165.0 2.611398
4226 Austria 2020-04-14 NaN 14389.0 NaN 8590.0 450.0 8840521.0 162.761901 5.090198 3.127389 NaN NaN 150.0 1.696733
2484 Germany 2020-02-01 NaN 12.0 NaN 12.0 0.0 82905782.0 0.014474 0.000000 0.000000 NaN NaN 1.0 0.001206
5425 United Kingdom 2021-04-04 37013749.0 4439471.0 127143632.0 NaN 127655.0 66460344.0 6679.879659 192.076947 2.875455 191307.514147 0.556930 2412.0 3.629232
1215 Belgium 2021-02-21 750465.0 752879.0 9212254.0 NaN 22218.0 11433256.0 6584.992062 194.327845 2.951072 80574.195137 0.065639 805.0 7.040864

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_url).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:N', 'confirmed_per:Q'],
    color=alt.Color('id:N', legend=alt.Legend(title="Countries")),
    opacity=alt.condition(leg_selection, alt.value(1), alt.value(0.2))
).transform_filter(alt.datum.confirmed_per>0).add_selection(leg_selection).properties(title='Total number of cases per 100,000 population for selected European Countries', width=600).interactive()

Total deaths per 100,000

alt.Chart(x_small_url).mark_line().encode(
    x=alt.X("yearmonthdate(date):T", axis=alt.Axis(title='Date')),
    y=alt.Y("deaths_per:Q", axis=alt.Axis(title='Deaths per 100k'), impute=alt.ImputeParams(value=50)),
    tooltip=["id:N", "deaths_per:Q", "yearmonthdate(date):T"],
    color=alt.Color('id:N', legend=alt.Legend(title="Countries")),
    opacity=alt.condition(leg_selection, alt.value(1), alt.value(0.2))
).transform_filter(alt.datum.deaths_per>0).add_selection(leg_selection).properties(title='Number of deaths per 100,000 population for selected European Countries', width=600).interactive()

Two week incidence rate

brush = alt.selection(type='interval', encodings=['x'])

base = alt.Chart(x_small_url).mark_line().transform_filter(alt.datum.new_cases_per>0).transform_window(
    rolling_mean='sum(new_cases_per)',
    frame=[-14, 0],
    groupby=['id:N']
).encode(
    x=alt.X("yearmonthdate(date):T",
            axis=alt.Axis(title='Date')
           ),
    y=alt.Y("rolling_mean:Q",
            axis=alt.Axis(title='Incidence rate')
           ),
    tooltip=['id:N', 'rolling_mean:Q'],
    color=alt.Color('id:N', legend=alt.Legend(title="Countries")),
    opacity=alt.condition(leg_selection, alt.value(1), alt.value(0.2))
).add_selection(leg_selection).properties(
    width=600,
    height=400,
    title='Number of new cases per 100,000 over two weeks for selected countries'
)

upper = base.encode(
    alt.X('yearmonthdate(date):T',axis=alt.Axis(title='Date'),
          scale=alt.Scale(domain=brush))
)

lower = base.properties(
    height=60
).add_selection(brush)

upper & lower

The ratio of confirmed cases and deaths gives an indication of what the case fatality rate is - it seems to be between 2 and 3%, assuming that the countries listed here are catching all positive cases (which they probably aren't, so it's likely lower than this).

Case fatality rate

base = alt.Chart(x_small_url).mark_line().transform_filter(alt.datum.ratio>0).encode(
    x=alt.X("yearmonthdate(date):T", axis=alt.Axis(title='Date')),
    y=alt.Y("ratio:Q", axis=alt.Axis(title='Ratio of deaths per case')),
    tooltip='id:N',
    color=alt.Color('id:N', legend=alt.Legend(title="Countries")),
opacity=alt.condition(leg_selection, alt.value(1), alt.value(0.2))
).add_selection(leg_selection).properties(title='The ratio of deaths to confirmed cases (case fatality rate)', width=600)

upper = base.encode(
    alt.X('yearmonthdate(date):T',axis=alt.Axis(title='Date'),
          scale=alt.Scale(domain=brush))
)

lower = base.properties(
    height=60
).add_selection(brush)

upper & lower

Vaccines

In the chart below we plot the number vaccines given per population - this means that if the number is 1, then the country has given the equivalent of 1 shot for each person in the country. Since not everyone in the countries are eligible to get the vaccine, a ratio of 1 means that many people have recieved two jabs. Note also that some kinds of vaccines (the J&J's Janssen vaccine, for example) only require 1 shot so the goal is not neccesarily to reach exactly 2 shots per person in the whole country.

alt.Chart(x_small_url).mark_line().transform_filter(alt.datum.vaccines_per>0).encode(
    x=alt.X("yearmonthdate(date):T", axis=alt.Axis(title='Date')),
    y=alt.Y("vaccines_per:Q", axis=alt.Axis(title='Number of vaccines given')),
    tooltip=['id:N', 'vaccines_per:Q'],
    color=alt.Color('id:N', legend=alt.Legend(title="Countries")),
    opacity=alt.condition(leg_selection, alt.value(1), alt.value(0.2))
).add_selection(leg_selection).properties(title='Number of vaccines given', width=600).interactive()