Per Capita COVID-19 cases worldwide
GIS plot of per capita cases of COVID-19 all over the world
Today we will make the Per Capita covid cases worldwide from the article Coronavirus Map: Tracking the Global Outbreak that looks like the following -
import altair as alt
import pandas as pd
import geopandas as gpd
alt.renderers.set_embed_options(actions=False)
We will use the JHU CSSE Dataset for the cases as well as the population. For the map we will use the shapefiles from Natural Earth.
population_uri = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/UID_ISO_FIPS_LookUp_Table.csv'
population_data = pd.read_csv(population_uri)
latest_cases_uri = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/10-29-2020.csv'
latest_cases = pd.read_csv(latest_cases_uri)
world_shapefile_uri = "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip"
world = gpd.read_file(world_shapefile_uri)
We have to make some changes so that we get things right. For example there's quite a few names to change for the countries because the cases dataset doesn't have identifier informations. Then in the map file we have to merge a few countries and segregate a few based on how JHU CSSE reports their cases.
latest_cases.head()
latest_cases[latest_cases['Country_Region'].str.contains('Denmark')]
latest_cases.loc[latest_cases['Province_State']=='Greenland', 'Country_Region'] = "Greenland"
population_data.loc[population_data['Province_State']=='Greenland', 'Country_Region'] = "Greenland"
population_data.loc[population_data['Province_State']=='Greenland', 'Combined_Key'] = "Greenland"
latest_cases = latest_cases.drop(['FIPS', 'Admin2', 'Province_State', 'Last_Update', 'Lat', 'Long_', 'Combined_Key', 'Incidence_Rate', 'Case-Fatality_Ratio'], axis=1)
latest_cases = latest_cases.groupby('Country_Region').aggregate({'Confirmed': 'sum', 'Recovered': 'sum', 'Deaths': 'sum', 'Active': 'sum', })
latest_cases = latest_cases.reset_index()
latest_cases.head()
world = world[~(world['CONTINENT']=='Antarctica')]
world = world[['SOVEREIGNT', 'ADMIN', 'NAME', 'POP_EST', 'POP_YEAR', 'ISO_A3', 'CONTINENT', 'geometry']]
world.head()
alt.Chart(world).mark_geoshape(stroke='white').encode().project('equalEarth')
world[world['NAME'].str.contains('Green')]
somalia = world[world['NAME'].str.contains('Somali')]
somalia = somalia.dissolve(by='CONTINENT').reset_index()
somalia
world=pd.concat([world, somalia])
alt.Chart(somalia).mark_geoshape().encode()
world.loc[world['ADMIN'].str.contains('eSwatini'), 'ADMIN'] = 'Eswatini'
world.loc[world['ADMIN'].str.contains('Palestine'), 'ADMIN'] = 'West Bank and Gaza'
world.loc[world['ADMIN'].str.contains('Republic of Serbia'), 'ADMIN'] = 'Serbia'
world.loc[world['ADMIN'].str.contains('United Republic of Tanzania'), 'ADMIN'] = 'Tanzania'
world.loc[world['ADMIN'].str.contains('São Tomé and Principe'), 'ADMIN'] = 'Sao Tome and Principe'
latest_cases.loc[latest_cases['Country_Region']=='Korea, South', 'Country_Region'] = 'South Korea'
latest_cases.loc[latest_cases['Country_Region']=="Cote d'Ivoire", 'Country_Region'] = 'Ivory Coast'
latest_cases.loc[latest_cases['Country_Region']=='Timor-Leste', 'Country_Region'] = 'East Timor'
latest_cases.loc[latest_cases['Country_Region']=='Taiwan*', 'Country_Region'] = 'Taiwan'
latest_cases.loc[latest_cases['Country_Region']=='Burma', 'Country_Region'] = 'Myanmar'
latest_cases.loc[latest_cases['Country_Region']=='US', 'Country_Region'] = 'United States of America'
latest_cases.loc[latest_cases['Country_Region']=='Czech Republic', 'Country_Region'] = 'Czechia'
latest_cases.loc[latest_cases['Country_Region']=='North Macedonia', 'Country_Region'] = 'Macedonia'
latest_cases.loc[latest_cases['Country_Region']=='Bahamas', 'Country_Region'] = 'The Bahamas'
latest_cases.loc[latest_cases['Country_Region']=='Congo (Kinshasa)', 'Country_Region'] = 'Democratic Republic of the Congo'
latest_cases.loc[latest_cases['Country_Region']=='Congo (Brazzaville)', 'Country_Region'] = 'Republic of the Congo'
latest_cases[latest_cases['Country_Region'].isin(world['ADMIN']) == False]
Extracting population data for countries -
population_data = population_data.drop(['UID', 'code3', 'FIPS', 'Admin2', 'Province_State', 'Lat', 'Long_'], axis=1)
population_data = population_data[population_data['Country_Region'] == population_data['Combined_Key']]
population_data = population_data.reset_index(drop=True)
population_data.head()
population_data.loc[population_data['Country_Region']=='Taiwan*', 'Country_Region'] = 'Taiwan'
population_data.loc[population_data['Country_Region']=='Korea, South', 'Country_Region'] = 'South Korea'
population_data.loc[population_data['Country_Region']=="Cote d'Ivoire", 'Country_Region'] = 'Ivory Coast'
population_data.loc[population_data['Country_Region']=='Timor-Leste', 'Country_Region'] = 'East Timor'
population_data.loc[population_data['Country_Region']=='US', 'Country_Region'] = 'United States of America'
population_data.loc[population_data['Country_Region']=='Czech Republic', 'Country_Region'] = 'Czechia'
population_data.loc[population_data['Country_Region']=='Burma', 'Country_Region'] = 'Myanmar'
population_data.loc[population_data['Country_Region']=='North Macedonia', 'Country_Region'] = 'Macedonia'
population_data.loc[population_data['Country_Region']=='Bahamas', 'Country_Region'] = 'The Bahamas'
population_data.loc[population_data['Country_Region']=='Congo (Kinshasa)', 'Country_Region'] = 'Democratic Republic of the Congo'
population_data.loc[population_data['Country_Region']=='Congo (Brazzaville)', 'Country_Region'] = 'Republic of the Congo'
world.columns = ['SOVEREIGNT', 'Country_Region', 'NAME', 'POP_EST', 'POP_YEAR', 'ISO_A3', 'CONTINENT', 'geometry']
world = world.merge(latest_cases, on='Country_Region', how='left')
world = world.merge(population_data, on='Country_Region', how='left')
world['per_capita'] = world['Confirmed']/world['Population']
world.head()
world['code'] = world['per_capita'].apply(lambda x: 'Less than 1 in 1000' if x <= (1/1000) else 'Less than 1 in 500' if x<= (1/500) else 'Less than 1 in 333' if x<= (1/333) else 'No Cases reported' if pd.isnull(x) else 'Greater than 1 in 333')
world['Share of Population'] = world['Population']/world['Confirmed']
world['Share of Population'] = world['Share of Population'].round()
world['Share of Population'] = world['Share of Population'].apply(lambda x: f"1 in {str(x).split('.')[0]}")
alt.Chart(world).mark_geoshape(stroke='white').transform_filter(alt.datum.Country_Region != 'Antarctica').encode(
color=alt.Color('code:N', scale=alt.Scale(domain=['No Cases reported', 'Less than 1 in 1000', 'Less than 1 in 500', 'Less than 1 in 333', 'Greater than 1 in 333'], range=['lightgrey', '#f2df91', '#ffae43', '#ff6e0b', '#ce0a05']),legend=alt.Legend(title=None, orient='top', labelBaseline='middle', symbolType='square', columnPadding=20, labelFontSize=15, gridAlign='each', symbolSize=200)),
tooltip = ['Country_Region', 'Confirmed', 'Share of Population']
).properties(width=1400, height=800).project('equalEarth').configure_view(strokeWidth=0)