<jupyter_start><jupyter_text>Take Home ExamName: <NAME> (i6197039) |Date: 09/02/2022  IntroductionResearch question:***How have the Government Response Stringency Index influenced the new confirmed cases of COVID-19 per million in different Western European countries in 2020?**** Stringency Index: * value from 0 - 100, composite measure based on nine response indicators (school closure, workplace closure, travel bans, etc.* New confirmed cases * per million  Data analysis:<jupyter_code>#import the essential packages I need for my analysis
import altair as alt
import pandas as pd
import ipywidgets as widgets
from ipywidgets import interact
from ipywidgets import fixed
#read the COVID data and stored in variable
Covid = pd.read_csv("https://covid.ourworldindata.org/data/owid-covid-data.csv", parse_dates=['date'])
Covid
#checked the unique values of de continent columns to see if there are strange values
Covid.continent.unique()
#only included Europe and the relevant columns in a new dataframe
included_continent = ['Europe']
included_columns = ['iso_code', 'continent', 'location', 'date', 'stringency_index', 
                    'new_cases_per_million', 'population', 'median_age']
Covid_EU = Covid.loc[Covid.continent.isin(included_continent) & (Covid.date.dt.year == 2020), included_columns]
Covid_EU
#checked the unique values of locations in EU, to find if there are strange values
Covid_EU.location.unique()
#made a new dataframe with only the counrties of West EU
included_countries = ['Ireland', 'United Kingdom', 'Germany', 'Netherlands', 'Belgium',
                      'Luxembourg', 'France', 'Austria', 'Slovenia']
included_columns = ['iso_code', 'continent', 'location', 'date', 'stringency_index', 
                    'new_cases_per_million', 'population', 'median_age']
Covid_West_EU = Covid_EU.loc[Covid_EU.location.isin(included_countries) & (Covid_EU.date.dt.year == 2020), included_columns]
Covid_West_EU
#checked the missing values in the datafram that I am interested in
Covid_West_EU.isnull().sum()
#only 39 rows of 2924 had missing values (only new cases), so I dropped them 
Covid_West_EU_cleaned = Covid_West_EU.dropna()
Covid_West_EU_cleaned
chart_cases_time= alt.Chart(Covid_West_EU_cleaned).mark_line().encode(
    x='date',
    y='new_cases_per_million',
    color ='location'
).interactive()
chart_cases_time
#made some descriptives of the interested variables per country
Descr_POP = Covid_West_EU_cleaned.groupby('location')['population'].describe()
Descr_MedAge = Covid_West_EU_cleaned.groupby('location')['median_age'].mean()
Descr_SI = Covid_West_EU_cleaned.groupby('location')['stringency_index'].describe()
Descr_NCPM = Covid_West_EU_cleaned.groupby('location')['new_cases_per_million'].describe()
Descr_POP
Descr_MedAge
Descr_SI
Descr_NCPM
#now I wanted to visualize the data in an interactive way

#firstly, I defined how to select the rows of locations from the df

def select_country(location, df):
  return df.loc[df['location'] == location, ]

#then the definition for the vizualization
def vizualize_country(location, df):

  filtered_data = select_country(location, df)

#then I created the two graphs for stringency_index and new_cases_per_million
  chart_stringency = alt.Chart(filtered_data).mark_point().encode(
    x='date',
    y='stringency_index',
    color = 'location'
  )
  
  chart_new_cases = alt.Chart(filtered_data).mark_point().encode(
    x='date',
    y='new_cases_per_million',
    color = 'location'
  ) 

#the two graphs will be displayed
  display(chart_stringency) 
  
  display(chart_new_cases)
#creating a list for the dropdown menu I will use in the following cell
country_list = Covid_West_EU_cleaned['location'].unique()
#to present the interactive graph I created a nice border
output_interactive_graph = widgets.Output(layout={'border': '2px solid blue'})

##within the output border I presented a text and the two graphs
###with the interactive dropdown menu of the locations in West EU
with output_interactive_graph:
  print("Choose a country in West EU to see the effect of Government Response") 
  print("Stringency Index on confirmed new COVID-19 cases per million in 2020")
  interact(vizualize_country, location=country_list, df=fixed(Covid_West_EU_cleaned))

output_interactive_graph<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09485157699443414, 'fraction_numerical': 0.010667903525046383, 'mean_word_length': 5.749608763693271, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '73332', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1308, 'n_words': 411, 'path': 'notebooks/Final_TakeHomeExam_JJohnmary_i6197039.ipynb', 'repo_name': 'JJ6197039/voila', 'size': '4319'}