|
7 | 7 | import pandas as pd |
8 | 8 | from pathlib import Path |
9 | 9 |
|
10 | | -# Paths |
11 | 10 | DATA_DIR = Path('docs/data') |
12 | 11 | INPUT_FILE = DATA_DIR / 'public_emdat_incl_hist_2026-03-17.xlsx' |
13 | 12 | OUTPUT_FILE = DATA_DIR / 'emdat_clean.csv' |
14 | 13 |
|
15 | | -# Configuration |
16 | 14 | SHEET_NAME = 'EM-DAT Data' |
17 | 15 | YEAR_START = 1975 |
18 | 16 | YEAR_END = 2025 |
19 | 17 |
|
20 | | -print('Creating emdat_clean.csv for website...') |
21 | 18 | print(f'Reading: {INPUT_FILE}') |
22 | 19 |
|
23 | | -# Load the Excel file |
24 | 20 | df_full = pd.read_excel(INPUT_FILE, sheet_name=SHEET_NAME) |
25 | 21 | print(f'Loaded {len(df_full):,} total records from Excel') |
26 | 22 |
|
27 | | -# Filter to analysis period and natural disasters only |
28 | 23 | df = df_full[ |
29 | 24 | (df_full['Start Year'].between(YEAR_START, YEAR_END, inclusive='both')) & |
30 | 25 | (df_full['Disaster Group'] == 'Natural') |
31 | 26 | ].copy() |
32 | 27 |
|
33 | 28 | print(f'Filtered to {YEAR_START}-{YEAR_END}, Natural disasters: {len(df):,} records') |
34 | 29 |
|
35 | | -# Select and rename columns for website |
36 | 30 | df_clean = df[[ |
37 | 31 | 'Start Year', 'ISO', 'Country', 'Region', 'Subregion', |
38 | 32 | 'Disaster Type', 'Disaster Subtype', 'Event Name', |
|
48 | 42 | 'lat', 'lon' |
49 | 43 | ] |
50 | 44 |
|
51 | | -# Map disaster types to website format (lowercase, simplified) |
52 | 45 | type_mapping = { |
53 | 46 | 'Flood': 'flood', |
54 | 47 | 'Storm': 'storm', |
|
57 | 50 | 'Earthquake': 'earthquake', |
58 | 51 | 'Volcanic activity': 'volcano', |
59 | 52 | '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', |
64 | 57 | } |
65 | 58 |
|
66 | 59 | df_clean['type'] = df_clean['type'].map(type_mapping) |
|
77 | 70 | df_clean['affected'] = df_clean['affected'].fillna(0) |
78 | 71 | df_clean['damage_usd_thousands'] = df_clean['damage_usd_thousands'].fillna(0) |
79 | 72 |
|
80 | | -# Save to CSV |
81 | 73 | df_clean.to_csv(OUTPUT_FILE, index=False) |
82 | 74 |
|
83 | 75 | print(f'\n✓ Saved: {OUTPUT_FILE}') |
84 | 76 | print(f'✓ Records: {len(df_clean):,}') |
85 | 77 | print(f'✓ Year range: {int(df_clean["year"].min())}-{int(df_clean["year"].max())}') |
86 | 78 | print(f'✓ Countries: {df_clean["iso"].nunique()}') |
87 | 79 |
|
88 | | -# Show disaster type distribution |
89 | 80 | print('\nDisaster type distribution:') |
90 | 81 | type_counts = df_clean['type'].value_counts() |
91 | 82 | for dtype, count in type_counts.items(): |
92 | 83 | print(f' {dtype}: {count:,} ({count/len(df_clean)*100:.1f}%)') |
93 | 84 |
|
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