In [1]:
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import plotly
import numpy as np
In [2]:
# load Alcohol, total per capita (15+) consumption (in litres of pure alcohol) data
df_alcohol = pd.read_csv('data2018.csv')
df_alcohol.head()
Out[2]:
Country Continent Both sexes Male Female CODE Pop Age of drinking GDP per Capita
0 Afghanistan Asia 0.2 0.4 0.1 AFG 37171921 100.0 494
1 Albania Europe 7.2 11.6 2.7 ALB 2882740 18.0 5284
2 Algeria Africa 0.9 1.6 0.3 DZA 42228408 18.0 4154
3 Andorra Europe 11.0 17.2 5.2 AND 77006 18.0 41793
4 Angola Africa 6.9 11.0 3.1 AGO 30809787 18.0 3290
In [3]:
# set index and loc useful columns
df_a=df_alcohol[['CODE', 'Both sexes','Country']]
a=df_a.set_index('CODE').loc[:, 'Both sexes']
In [4]:
# generate a choropleth graph of the world alcohol consumption in 2018
fig = go.Figure(data=go.Choropleth(
    locations = df_a['CODE'],
    z = a,
    text = df_a['Country'],
    colorscale = 'Blues',
    autocolorscale=False,
    reversescale=True,
    marker_line_color='darkgray',
    marker_line_width=0.5,
    colorbar_ticksuffix = 'L',
    colorbar_title = 'Alcohol<br>Liters',
))

fig.update_layout(
    title_text='Alcohol, total per capita (15+) consumption, 2018',
    geo=dict(
        showframe=False,
        showcoastlines=False,
        projection_type='equirectangular'
    ),
    annotations = [dict(
        x=0.55,
        y=0.1,
        xref='paper',
        yref='paper',
        text='Source: <a href="https://apps.who.int/gho/data/node.main.A1039?lang=en">\
            World Health Orgnization</a>',
        showarrow = False
    )]
)

fig.show()
plotly.io.write_html(fig,"alcoholc.html", full_html=False)
In [5]:
# generate a scatter graph of alcohol, per capita consumption by sexs
fig = px.scatter(df_alcohol, x="Female", y="Male",
                 size="Pop", color="Continent",
                 hover_name="Country", log_x=False, size_max=50, 
                 title="Alcohol, per capita consumption by males vs. females, 2018")
fig.show()
plotly.io.write_html(fig,"gender.html", full_html=False)
In [6]:
# generate a scatter graph of alcohol, per capita consumption by both sexes vs. legal drinking age
fig = px.scatter(df_alcohol, x="Both sexes", y="Age of drinking",
                 size="Pop", color="Continent",
                 hover_name="Country", log_x=False, size_max=50,
                title="Alcohol, per capita consumption by both sexes vs. legal age of drinking, 2018")
fig.show()
plotly.io.write_html(fig,"age.html", full_html=False)
In [7]:
# generate a scatter graph of alcohol, per capita consumption by both sexes vs. GDP per capita, 2018
fig = px.scatter(df_alcohol, x="GDP per Capita", y="Both sexes",
                 size="Pop", color="Continent",
                 hover_name="Country", log_x=True, size_max=50,
                title="Alcohol, per capita consumption by both sexes vs. GDP per capita, 2018")
fig.show()
plotly.io.write_html(fig,"age.html", full_html=False)