Skip to content

Commit 6a0f1d3

Browse files
milestone2
1 parent e87fed8 commit 6a0f1d3

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

milestones/milestone-2/create_emdat_clean.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,26 @@
77
import pandas as pd
88
from pathlib import Path
99

10-
# Paths
1110
DATA_DIR = Path('docs/data')
1211
INPUT_FILE = DATA_DIR / 'public_emdat_incl_hist_2026-03-17.xlsx'
1312
OUTPUT_FILE = DATA_DIR / 'emdat_clean.csv'
1413

15-
# Configuration
1614
SHEET_NAME = 'EM-DAT Data'
1715
YEAR_START = 1975
1816
YEAR_END = 2025
1917

20-
print('Creating emdat_clean.csv for website...')
2118
print(f'Reading: {INPUT_FILE}')
2219

23-
# Load the Excel file
2420
df_full = pd.read_excel(INPUT_FILE, sheet_name=SHEET_NAME)
2521
print(f'Loaded {len(df_full):,} total records from Excel')
2622

27-
# Filter to analysis period and natural disasters only
2823
df = df_full[
2924
(df_full['Start Year'].between(YEAR_START, YEAR_END, inclusive='both')) &
3025
(df_full['Disaster Group'] == 'Natural')
3126
].copy()
3227

3328
print(f'Filtered to {YEAR_START}-{YEAR_END}, Natural disasters: {len(df):,} records')
3429

35-
# Select and rename columns for website
3630
df_clean = df[[
3731
'Start Year', 'ISO', 'Country', 'Region', 'Subregion',
3832
'Disaster Type', 'Disaster Subtype', 'Event Name',
@@ -48,7 +42,6 @@
4842
'lat', 'lon'
4943
]
5044

51-
# Map disaster types to website format (lowercase, simplified)
5245
type_mapping = {
5346
'Flood': 'flood',
5447
'Storm': 'storm',
@@ -57,10 +50,10 @@
5750
'Earthquake': 'earthquake',
5851
'Volcanic activity': 'volcano',
5952
'Landslide': 'landslide',
60-
'Extreme temperature': 'drought', # Map to drought category
61-
'Mass movement (dry)': 'landslide', # Map to landslide category
62-
'Glacial lake outburst': 'flood', # Map to flood category
63-
'Fog': 'storm', # Map to storm category
53+
'Extreme temperature': 'drought',
54+
'Mass movement (dry)': 'landslide',
55+
'Glacial lake outburst': 'flood',
56+
'Fog': 'storm',
6457
}
6558

6659
df_clean['type'] = df_clean['type'].map(type_mapping)
@@ -77,18 +70,16 @@
7770
df_clean['affected'] = df_clean['affected'].fillna(0)
7871
df_clean['damage_usd_thousands'] = df_clean['damage_usd_thousands'].fillna(0)
7972

80-
# Save to CSV
8173
df_clean.to_csv(OUTPUT_FILE, index=False)
8274

8375
print(f'\n✓ Saved: {OUTPUT_FILE}')
8476
print(f'✓ Records: {len(df_clean):,}')
8577
print(f'✓ Year range: {int(df_clean["year"].min())}-{int(df_clean["year"].max())}')
8678
print(f'✓ Countries: {df_clean["iso"].nunique()}')
8779

88-
# Show disaster type distribution
8980
print('\nDisaster type distribution:')
9081
type_counts = df_clean['type'].value_counts()
9182
for dtype, count in type_counts.items():
9283
print(f' {dtype}: {count:,} ({count/len(df_clean)*100:.1f}%)')
9384

94-
print('\n Done! The website can now load the data from emdat_clean.csv')
85+
print('\n Done! The website can now load the data from emdat_clean.csv')

0 commit comments

Comments
 (0)