natural disasters
Tags: #emdat #opendata #analytics
Author: MyDigitalSchool
In 1988, the Centre for Research on the Epidemiology of Disasters (CRED) launched the Emergency Events Database (EM-DAT). EM-DAT was created with the initial support of the World Health Organisation (WHO) and the Belgian Government.

Input

In order to use this script, you need to download the dataset on this link : https://public.emdat.be/
  • Create an account and connect
  • Go to "Data" tab
  • Enter your filters criteria
  • Press "Download"

Import librairies

1
import pandas as pd
2
import plotly.express as px
Copied!

Variable

1
PATH_CSV = 'path_to_your_file.csv'
Copied!

Model

Read the CSV

1
df = pd.read_csv(PATH_CSV)
Copied!

Configure the plot

1
# Types
2
types_df = df[['Year', 'Disaster Type']]
3
total_line = types_df[['Year']].value_counts().reset_index(name="value")
4
total_line['Disaster Type'] = "All"
5
types_df = types_df.groupby(['Year', 'Disaster Type']).size().reset_index(name="value")
6
types_df = types_df.append(total_line).sort_values(by=["Year"])
7
8
# Countries
9
count_by_countries = df[['Year', 'ISO', 'Country']].groupby(['Year', 'ISO', 'Country']).size().reset_index(name='counts')
Copied!

Output

1
fig = px.choropleth(
2
count_by_countries, locations="ISO",
3
color="counts",
4
hover_name="Country",
5
animation_frame="Year",
6
title = "Number of natural disasters per country",
7
color_continuous_scale=px.colors.sequential.OrRd,
8
range_color=[0, count_by_countries['counts'].max()]
9
)
10
11
fig.update_layout(
12
width=850,
13
height=600,
14
autosize=False,
15
template="plotly_white",
16
title_x=0.5
17
)
18
fig.show()
Copied!
1
common_kwargs = {'x': "Year", 'y': "value", 'title': "Number of natural disasters per year"}
2
3
line_fig = px.line(types_df[types_df['Disaster Type'] == "All"], **common_kwargs)
4
lineplt_all = px.line(types_df[types_df['Disaster Type'] == "All"], **common_kwargs)
5
lineplt_filtered = {
6
disaster_type: px.line(types_df[types_df['Disaster Type'] == disaster_type], **common_kwargs)
7
for disaster_type in types_df['Disaster Type'].unique() if disaster_type != "All"
8
}
9
# Add dropdown
10
line_fig.update_layout(
11
updatemenus=[
12
dict(
13
buttons=list(
14
[
15
dict(
16
label="All disasters",
17
method="restyle",
18
args=[{
19
"y": [data.y for data in lineplt_all.data]
20
}]
21
)
22
] + [
23
dict(
24
label=disaster_type,
25
method="restyle",
26
args=[
27
{
28
"y": [data.y for data in lineplt.data],
29
}
30
]
31
)
32
for disaster_type, lineplt in lineplt_filtered.items()
33
]
34
),
35
),
36
],
37
title_x=0.5,
38
plot_bgcolor='rgba(0,0,0,0)',
39
)
40
line_fig.update_xaxes(gridcolor="grey")
41
line_fig.update_yaxes(gridcolor="grey")
42
line_fig.show()
Copied!
Idea of improvements :
  • Put all the curves of natural disasters in a logarithmic graph
Last modified 2mo ago
Copy link
Edit on GitHub