# import our map function
from interactive_maps import choropleth_map
# others
import pandas as pd
import geopandas as gpd
from glob import glob
data: "Recorder alcohol per capita consumption" from Global Health Observatory data repository
# read files
data = pd.DataFrame()
for filename in glob("data-verbose*.csv"):
temp = pd.read_csv(filename)
data = data.append(temp)
data.columns
data["ALCOHOLTYPE (DISPLAY)"].unique()
# all types of alcohol combined
data = data.loc[data["ALCOHOLTYPE (DISPLAY)"] == 'All types']
# only keep columns of interest
data = data[['YEAR (CODE)','COUNTRY (CODE)','COUNTRY (DISPLAY)','Numeric']]
data.reset_index(inplace=True, drop=True)
data.rename(columns={
'YEAR (CODE)': 'Year',
'COUNTRY (CODE)': 'Code',
'COUNTRY (DISPLAY)': 'Country',
'Numeric': 'Value'
}, inplace=True)
data.head()
data[data["Value"].isna()]["Country"].unique()
# read shapes
geo = gpd.read_file("../ne_110m_admin_0_countries.shp")[['ADMIN', 'ADM0_A3', 'geometry']]
geo.columns = ['Country', 'Code', 'geometry']
geo.head()
geo = geo.loc[~(geo['Country'] == 'Antarctica')]
data["Value"].describe()
# Create bins to color each country
bins = [0, 1, 3, 6, 10, 15, 20, 1e2]
choropleth_map(
data, geo,
bins=bins, bin_labels="L",
notebook=True, size=(900,450),
value_title="Litres of pure alcohol per capita",
value_axis_label="Litres of pure alcohol per capita",
map_title="Alcohol consumption per capita in {}",
chart_title="Evolution of alcohol consumption per capita",
map_palette="YlGnBu", default_map_year=2016,
)