read the data on github.com/owid/covid-19-data...vaccinations/country_data
from datetime import datetime
start_time = datetime.now()
print("Last run: ", start_time)
Last run: 2020-12-25 09:44:52.466671
import pandas as pd
GITHUB_directory = "https://api.github.com/repos/owid/covid-19-data/contents/public/data/vaccinations/country_data"
countries = pd.read_json(GITHUB_directory)
listcountries = []
for index,row in countries.iterrows():
df = pd.read_csv(row["download_url"])
listcountries.append(df)
allCountries = pd.concat(listcountries, axis=0, ignore_index=True)
# Show 15 latest sorted by dates
allCountries.sort_values(by=['date'],ascending=False)[0:15]
location | date | vaccine | total_vaccinations | source_url | |
---|---|---|---|---|---|
26 | United Kingdom | 2020-12-24 | Pfizer/BioNTech | 800000 | https://www.gov.uk/government/speeches/prime-m... |
1 | Bahrain | 2020-12-24 | Sinopharm | 50071 | https://twitter.com/MOH_Bahrain/status/1342189... |
0 | Bahrain | 2020-12-23 | Sinopharm | 38965 | https://twitter.com/MOH_Bahrain/status/1341855... |
27 | United States | 2020-12-23 | Moderna, Pfizer/BioNTech | 1008025 | https://covid.cdc.gov/covid-data-tracker/#vacc... |
17 | Israel | 2020-12-23 | Pfizer/BioNTech | 140000 | https://twitter.com/YuliEdelstein/status/13418... |
11 | Canada | 2020-12-23 | Pfizer/BioNTech | 31736 | https://github.com/ishaberry/Covid19Canada/blo... |
10 | Canada | 2020-12-22 | Pfizer/BioNTech | 26287 | https://github.com/ishaberry/Covid19Canada/blo... |
16 | Israel | 2020-12-22 | Pfizer/BioNTech | 71876 | https://www.gov.il/en/departments/news/2212202... |
28 | United States | 2020-12-21 | Moderna, Pfizer/BioNTech | 614117 | https://covid.cdc.gov/covid-data-tracker/#vacc... |
9 | Canada | 2020-12-21 | Pfizer/BioNTech | 20866 | https://github.com/ishaberry/Covid19Canada/blo... |
15 | Israel | 2020-12-21 | Pfizer/BioNTech | 30000 | https://www.gov.il/en/departments/news/2212202... |
8 | Canada | 2020-12-20 | Pfizer/BioNTech | 14492 | https://github.com/ishaberry/Covid19Canada/blo... |
25 | United Kingdom | 2020-12-20 | Pfizer/BioNTech | 616933 | https://coronavirus.data.gov.uk/ |
29 | United States | 2020-12-20 | Moderna, Pfizer/BioNTech | 556208 | https://www.cdc.gov/coronavirus/2019-ncov/vacc... |
23 | Scotland | 2020-12-20 | Pfizer/BioNTech | 56676 | https://coronavirus.data.gov.uk/ |
#Countries in list
allCountries["location"].value_counts()
Canada 10 United States 4 Israel 4 Russia 3 Scotland 2 United Kingdom 2 Bahrain 2 Wales 2 Northern Ireland 2 England 1 China 1 Name: location, dtype: int64
allCountries.groupby(["location", "vaccine"]).size()
location vaccine Bahrain Sinopharm 2 Canada Pfizer/BioNTech 10 China CNBG, Sinovac 1 England Pfizer/BioNTech 1 Israel Pfizer/BioNTech 4 Northern Ireland Pfizer/BioNTech 2 Russia Sputnik V 3 Scotland Pfizer/BioNTech 2 United Kingdom Pfizer/BioNTech 2 United States Moderna, Pfizer/BioNTech 4 Wales Pfizer/BioNTech 2 dtype: int64
allCountries['date'] = allCountries['date'].astype('datetime64[ns]')
# Filter away Wales , England, Scotland see above and [issue 228](https://github.com/owid/covid-19-data/issues/228)
list_of_countries_to_delete = ["England","Northern Ireland","Scotland","Wales"]
allCountriesFiltered = allCountries[~allCountries["location"].isin(list_of_countries_to_delete)]
allCountriesFiltered.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 26 entries, 0 to 30 Data columns (total 5 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 location 26 non-null object 1 date 26 non-null datetime64[ns] 2 vaccine 26 non-null object 3 total_vaccinations 26 non-null int64 4 source_url 26 non-null object dtypes: datetime64[ns](1), int64(1), object(3) memory usage: 1.2+ KB
#Countries
%matplotlib inline
import matplotlib.pyplot as plt
#Reported numbers are accumulated --> get latest
plotCountries = allCountriesFiltered.sort_values(by=['date'],ascending=False) \
[['total_vaccinations','location','vaccine']].groupby('location').apply(lambda x: x.head(1))
plotCountries = plotCountries.set_index('location')
plotCountries["total_vaccinations"].plot( y='location',kind = 'pie')
plt.title("Vaccination per countries - " + start_time.strftime('%Y %m %d'))
plt.savefig('Corona_VaccinationperCountry.png')
plt.show()
plotCountries.sort_values(by='total_vaccinations',ascending=True)
total_vaccinations | vaccine | |
---|---|---|
location | ||
Canada | 31736 | Pfizer/BioNTech |
Bahrain | 50071 | Sinopharm |
Israel | 140000 | Pfizer/BioNTech |
Russia | 200000 | Sputnik V |
United Kingdom | 800000 | Pfizer/BioNTech |
China | 1000000 | CNBG, Sinovac |
United States | 1008025 | Moderna, Pfizer/BioNTech |
plotCountries.sum()
total_vaccinations 3229832 vaccine SinopharmPfizer/BioNTechCNBG, SinovacPfizer/Bi... dtype: object
# Vaccine numbers
plotVaccine = plotCountries.groupby('vaccine')['total_vaccinations'].sum()
plotVaccine.plot( kind = 'pie')
plt.title("Vaccination per Vaccine - " + start_time.strftime('%Y %m %d'))
plt.savefig('Corona_VaccinationperVaccine.png')
plt.show()
plotVaccine.sort_values(ascending=True)
vaccine Sinopharm 50071 Sputnik V 200000 Pfizer/BioNTech 971736 CNBG, Sinovac 1000000 Moderna, Pfizer/BioNTech 1008025 Name: total_vaccinations, dtype: int64
# Sweden have 10 000 doses....
end = datetime.now()
print("Ended: ", end)
print('Time elapsed (hh:mm:ss.ms) {}'.format(datetime.now() - start_time))
Ended: 2020-12-25 09:44:53.930888 Time elapsed (hh:mm:ss.ms) 0:00:01.464611
ourworldindata = "https://covid.ourworldindata.org/data/owid-covid-data.json"
#df_ourworldindata = pd.read_json(ourworldindata)
#df_ourworldindata.info()