import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import plotly
import numpy as np
# load Alcohol, total per capita (15+) consumption (in litres of pure alcohol) data
df_alcohol = pd.read_csv('data2018.csv')
df_alcohol.head()
# set index and loc useful columns
df_a=df_alcohol[['CODE', 'Both sexes','Country']]
a=df_a.set_index('CODE').loc[:, 'Both sexes']
# 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)
# 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)
# 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)
# 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)