This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| title = fill_title_and_subtitle("The Race Against Covid", "Visualizing Cumulative Statistics of Disease vs Vaccine") | |
| fig = go.Figure(data=[ | |
| go.Scatter( | |
| mode="lines+markers", | |
| name="Total Deaths", | |
| x=data['date'], | |
| y=data['cumulative_total_deaths'], | |
| marker_color="crimson", | |
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| title = fill_title_and_subtitle("Vaccine vs Virus", "Comparing the total number of daily new cases and daily vaccinations globally") | |
| fig = go.Figure(data=[ | |
| go.Bar( | |
| name="New Cases", | |
| x=data['date'], | |
| y=data['daily_new_cases'], | |
| marker_color="crimson", | |
| ), | |
| go.Bar( | |
| name="Vaccinated", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| countries = short.groupby('country')['total_vaccinations'].max().sort_values(ascending=False)[:10].index.tolist() | |
| title = get_multi_line_title("Vaccination Progress", "Rate of vaccinations for the top-10 vaccinated countries") | |
| line_plots = [] | |
| for c in countries: | |
| vacc_data = short[short.country == c] | |
| line_plots.append( | |
| go.Scatter( | |
| name = c, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime | |
| vaccs = vaccine_df.copy() | |
| daily = daily_df.copy() | |
| daily.head() | |
| # standardise the dates | |
| vaccs.date =vaccs.date.apply(lambda x: datetime.strptime(x, "%Y-%m-%d")) | |
| daily.date =daily.date.apply(lambda x: datetime.strptime(x, "%Y-%m-%d")) | |
| # use only common countries and dates | |
| countries = vaccs.dropna(subset=['daily_vaccinations'])['country'].unique() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| # unique dates | |
| dates = vaccine_df.date.unique().tolist() | |
| #For more smoother animations | |
| dates.extend(['2020-12-12', '2020-12-13']) | |
| # unique countries | |
| countries = vaccine_df.country.unique().tolist() | |
| # for easy processing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| title = ("Death Rates", "Percentage of the confired cases have died from Covid-19") | |
| data = summary_df.copy() | |
| data['death_rate'] = (data['total_deaths']/data['total_confirmed'])*100 | |
| data = data.dropna(subset=['death_rate']) | |
| fig = px.scatter_geo(data, locations="country", color="continent", | |
| locationmode='country names', | |
| hover_name="country", size="death_rate", | |
| projection="natural earth") | |
| fig.update_layout(title=title, title_x=0.45) | |
| fig.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fill_title_and_subtitle(title:str, subtitle:str): | |
| return f"{title}<br><sub>{subtitle}</sub>" | |
| def create_bar_chart(data: pd.DataFrame, xcolumn: str, ycolumn:str, title:str, colors:str, ylabel="Count", n=None): | |
| hovertemplate ='<br><b>%{x}</b>'+f'<br><b>{ylabel}: </b>'+'%{y}<br><extra></extra>' | |
| data = data.sort_values(ycolumn, ascending=False).dropna(subset=[ycolumn]) | |
| if n is not None: | |
| data = data.iloc[:n] | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #We will create an aggregated dataset by aggreagting the required columns using previous function. | |
| summary_cols = ['people_vaccinated', | |
| 'people_vaccinated_per_hundred', | |
| 'people_fully_vaccinated', | |
| 'people_fully_vaccinated_per_hundred', | |
| 'total_vaccinations_per_hundred', | |
| 'total_vaccinations'] | |
| summary = summary_df.set_index("country") | |
| vaccines = vaccine_df[['country', 'vaccines']].drop_duplicates().set_index('country') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vaccine_df.country = vaccine_df.country.replace().replace({ | |
| "Czechia": "Czech Republic", | |
| "United States": "USA", | |
| "United Kingdom": "UK", | |
| "Isle of Man": "Isle Of Man", | |
| "Republic of Ireland": "Ireland", | |
| "Northern Cyprus" : "Cyprus" | |
| }) | |
| #These 4 countries are a part of UK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def aggregate(df: pd.Series, agg_col: str) -> pd.DataFrame: | |
| data = df.groupby("country")[agg_col].max() | |
| data = pd.DataFrame(data) | |
| return data |
NewerOlder