Last active
March 21, 2021 15:53
-
-
Save kurasaiteja/1024a47a0fafd899e52d105d0389d01f to your computer and use it in GitHub Desktop.
This file contains 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() | |
dates = vaccs.dropna(subset=['daily_vaccinations'])['date'].unique() | |
country_mask = daily.country.apply(lambda x: x in countries) | |
date_mask = daily.date.apply(lambda x: x in dates) | |
# generate the visualization data | |
columns_to_sum = ['daily_new_cases', 'cumulative_total_cases', 'cumulative_total_deaths', 'active_cases'] | |
daily_cases = daily[country_mask & date_mask].groupby('date')[columns_to_sum].sum() | |
daily_vaccs = vaccs.groupby('date')[[ 'daily_vaccinations']].sum() | |
# make it a dataframe for convenience | |
data = pd.DataFrame(daily_cases).join(pd.DataFrame(daily_vaccs)) | |
# bring back the vaccine data we prepared in the previous section | |
cumulative_vaccines = pd.DataFrame(vaccines.groupby('date')['total_vaccinations'].sum()) | |
data = data.join(cumulative_vaccines).reset_index() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment