This Jupyter notebook describes how to access and visualize Infodengue's datasets using the Python language. For more information about the data and how to cite them, visit here.
To execute this notebook, the following libraries are necessary:
import pandas as pd
import numpy as np
Infodengue's tables have data aggregated by week, provided by different sources. They could be consulted by a form, or directly from Python, via consult of an API. This functionality is available via the URL: https://info.dengue.mat.br/api/alertcity?params: must contain the following parameters:
Every parameter mentioned so far is obligatory for the consultation. The following example shows the requisition of the register of dengue between 1 and 52 of the year 2020, in Rio de Janeiro (geocodigo = 3304557) on CSV: https://info.dengue.mat.br/api/alertcity?geocode=3304557&disease=dengue&format=csv&ew_start=1&ew_end=52&ey_start=2021&ey_end=2021
url = "https://info.dengue.mat.br/api/alertcity"
geocode = 3304557
disease = "dengue"
format = "csv"
ew_start = 1
ew_end = 53
ey_start = 2021
ey_end = 2021
params =(
"&disease="
+ f"{disease}"
+ "&geocode="
+ f"{geocode}"
+ "&disease="
+ f"{disease}"
+ "&format="
+ f"{format}"
+ "&ew_start="
+ f"{ew_start}"
+ "&ew_end="
+ f"{ew_end}"
+ "&ey_start="
+ f"{ey_start}"
+ "&ey_end="
+ f"{ey_end}"
)
url_resp = "?".join([url, params])
url_resp
'https://info.dengue.mat.br/api/alertcity?&disease=dengue&geocode=3304557&disease=dengue&format=csv&ew_start=1&ew_end=53&ey_start=2021&ey_end=2021'
dados = pd.read_csv(url_resp, index_col='SE')
dados.T
SE | 202101 | 202102 | 202103 | 202104 | 202105 | 202106 | 202107 | 202108 | 202109 | 202110 | ... | 202131 | 202132 | 202133 | 202134 | 202135 | 202136 | 202137 | 202138 | 202139 | 202140 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data_iniSE | 2021-01-03 | 2021-01-10 | 2021-01-17 | 2021-01-24 | 2021-01-31 | 2021-02-07 | 2021-02-14 | 2021-02-21 | 2021-02-28 | 2021-03-07 | ... | 2021-08-01 | 2021-08-08 | 2021-08-15 | 2021-08-22 | 2021-08-29 | 2021-09-05 | 2021-09-12 | 2021-09-19 | 2021-09-26 | 2021-10-03 |
casos_est | 9 | 11 | 14 | 30 | 18 | 17 | 17 | 25 | 23 | 32 | ... | 11 | 7 | 7 | 13 | 15 | 11 | 10 | 9 | 11 | 9 |
casos_est_min | 9 | 11 | 14 | 30 | 18 | 17 | 17 | 25 | 23 | 32 | ... | 11 | 7 | 7 | 12 | 14 | 9 | 7 | 5 | 6 | 2 |
casos_est_max | 9 | 11 | 14 | 30 | 18 | 17 | 17 | 25 | 23 | 32 | ... | 12 | 9 | 10 | 15 | 18 | 14 | 14 | 15 | 20 | 24 |
casos | 9 | 11 | 14 | 30 | 18 | 17 | 17 | 25 | 23 | 32 | ... | 11 | 8 | 7 | 12 | 14 | 9 | 7 | 5 | 5 | 1 |
p_rt1 | 0.642163 | 0.736372 | 0.825699 | 0.997716 | 0.567613 | 0.24269 | 0.293499 | 0.849171 | 0.717698 | 0.906233 | ... | 0.135919 | 0.130337 | 0.280614 | 0.850713 | 0.891939 | 0.454617 | 0.278808 | 0.275069 | 0.562253 | 0.423368 |
p_inc100k | 0.133377 | 0.163016 | 0.207475 | 0.444588 | 0.266753 | 0.251933 | 0.251933 | 0.37049 | 0.340851 | 0.474228 | ... | 0.163016 | 0.103737 | 0.103737 | 0.192655 | 0.222294 | 0.163016 | 0.148196 | 0.133377 | 0.163016 | 0.133377 |
Localidade_id | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
nivel | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | ... | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
id | 330455720210118913 | 330455720210218913 | 330455720210318913 | 330455720210418913 | 330455720210518913 | 330455720210618913 | 330455720210718913 | 330455720210818913 | 330455720210918913 | 330455720211018913 | ... | 330455720213118913 | 330455720213218913 | 330455720213318913 | 330455720213418913 | 330455720213518913 | 330455720213618913 | 330455720213718913 | 330455720213818913 | 330455720213918913 | 330455720214018913 |
versao_modelo | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | ... | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 | 2021-10-13 |
Rt | 1 | 1 | 1 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | ... | 1 | 1 | 1 | 2 | 2 | 1 | 1 | 1 | 1 | 1 |
pop | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | ... | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 | 6.74782e+06 |
tempmin | 24 | 24 | 24 | 25 | 24 | 22 | 24 | 23 | 24 | 23 | ... | 15 | 17 | 17 | 19 | 19 | 21 | 20 | NaN | NaN | NaN |
umidmax | 90 | 89 | 84 | 80 | 85 | 90 | 95 | 95 | 90 | 96 | ... | 93 | 95 | 95 | 92 | 93 | 92 | 94 | NaN | NaN | NaN |
receptivo | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
transmissao | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
nivel_inc | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
notif_accum_year | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | ... | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 | 1032 |
20 rows × 40 columns
# Filter Indicators
# Slicing data by epidemiological week
this_week = dados.index.max()
last_week = this_week - 1
cases_this_week = dados.loc[this_week]['casos_est']
cases_last_week = dados.loc[last_week]['casos_est']
print(dados.loc[last_week:].T)
SE 202139 202140 data_iniSE 2021-09-26 2021-10-03 casos_est 11 9 casos_est_min 6 2 casos_est_max 20 24 casos 5 1 p_rt1 0.562253 0.423368 p_inc100k 0.163016 0.133377 Localidade_id 0 0 nivel 1 1 id 330455720213918913 330455720214018913 versao_modelo 2021-10-13 2021-10-13 Rt 1 1 pop 6.74782e+06 6.74782e+06 tempmin NaN NaN umidmax NaN NaN receptivo 0 0 transmissao 0 0 nivel_inc 0 0 notif_accum_year 1032 1032
import plotly.graph_objects as go
from plotly.offline import iplot
trace1 = go.Scatter(
mode='lines+markers',
x=dados.index.map(
lambda v: '%s' % (str(v)[-6:])
),
y=dados['casos_est'],
name="Estimated cases",
marker_color='#1A5CF4',
hovertemplate=(
'%{text}' +
'<br>' +
'%{y:1f} Estimated cases' +
'<extra></extra>'
),
text="SE: " + dados.index.map(lambda v: '{}'.format(str(v)[-2:])) +
"<br>" +
"Date: " + dados.data_iniSE.loc[dados.index],
)
trace2 = go.Bar(
x=dados.index.map(
lambda v: '%s' % (str(v)[-6:])
),
y=dados['casos'],
name="Reported cases",
marker_color ='#BAF3FE',
marker_line_color='rgb(8,48,107)',
opacity=0.5,
hovertemplate=(
'%{text}' +
'<br>' +
'%{y:1f} Reported cases' +
'<extra></extra>'
),
text="SE: " + dados.index.map(lambda v: '{}'.format(str(v)[-2:])) +
"<br>" +
"Date: " + dados.data_iniSE.loc[dados.index],
)
trace3 = go.Indicator(
mode = "number+delta",
value = cases_this_week,
delta={
'reference': cases_last_week,
'increasing': {'color': "#e60000"},
'decreasing': {'color': "#1e824c"},
"font": {"size": 36},
},
title = {
"text": "SE:{} <br> Estimated cases".format(
str(this_week)[-2:]
)
},
domain = {'y': [0, 1], 'x': [0.25, 0.75]}
)
data = [trace1, trace2, trace3]
layout = go.Layout(
title_text='Total reported and estimated cases for Rio de Janeiro',
yaxis=dict(
title_text='Number of cases',
side = 'left',
showline=False,
showgrid=True,
showticklabels=True,
linecolor='rgb(204, 204, 204)',
linewidth=0,
gridcolor='rgb(176, 196, 222)',
),
xaxis=dict(
title_text='Epidemiological Week',
showline=False,
showgrid=True,
showticklabels=True,
tickangle=-60,
linecolor='rgb(204, 204, 204)',
linewidth=0,
gridcolor='rgb(176, 196, 222)',
),
showlegend=False,
plot_bgcolor='rgb(255, 255, 255)',
paper_bgcolor='rgb(245, 246, 249)',
autosize=True,
)
fig = go.Figure(data=data, layout=layout)
fig.show()