Skip to content

Commit 2f36083

Browse files
authored
Add files via upload
1 parent 4d63d84 commit 2f36083

File tree

1 file changed

+215
-0
lines changed

1 file changed

+215
-0
lines changed

hurricaneanalysis.py

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# names of hurricanes
2+
names = ['Cuba I', 'San Felipe II Okeechobee', 'Bahamas', 'Cuba II', 'CubaBrownsville', 'Tampico', 'Labor Day', 'New England', 'Carol', 'Janet', 'Carla', 'Hattie', 'Beulah', 'Camille', 'Edith', 'Anita', 'David', 'Allen', 'Gilbert', 'Hugo', 'Andrew', 'Mitch', 'Isabel', 'Ivan', 'Emily', 'Katrina', 'Rita', 'Wilma', 'Dean', 'Felix', 'Matthew', 'Irma', 'Maria', 'Michael']
3+
4+
# months of hurricanes
5+
months = ['October', 'September', 'September', 'November', 'August', 'September', 'September', 'September', 'September', 'September', 'September', 'October', 'September', 'August', 'September', 'September', 'August', 'August', 'September', 'September', 'August', 'October', 'September', 'September', 'July', 'August', 'September', 'October', 'August', 'September', 'October', 'September', 'September', 'October']
6+
7+
# years of hurricanes
8+
years = [1924, 1928, 1932, 1932, 1933, 1933, 1935, 1938, 1953, 1955, 1961, 1961, 1967, 1969, 1971, 1977, 1979, 1980, 1988, 1989, 1992, 1998, 2003, 2004, 2005, 2005, 2005, 2005, 2007, 2007, 2016, 2017, 2017, 2018]
9+
10+
# maximum sustained winds (mph) of hurricanes
11+
max_sustained_winds = [165, 160, 160, 175, 160, 160, 185, 160, 160, 175, 175, 160, 160, 175, 160, 175, 175, 190, 185, 160, 175, 180, 165, 165, 160, 175, 180, 185, 175, 175, 165, 180, 175, 160]
12+
13+
# areas affected by each hurricane
14+
areas_affected = [['Central America', 'Mexico', 'Cuba', 'Florida', 'The Bahamas'], ['Lesser Antilles', 'The Bahamas', 'United States East Coast', 'Atlantic Canada'], ['The Bahamas', 'Northeastern United States'], ['Lesser Antilles', 'Jamaica', 'Cayman Islands', 'Cuba', 'The Bahamas', 'Bermuda'], ['The Bahamas', 'Cuba', 'Florida', 'Texas', 'Tamaulipas'], ['Jamaica', 'Yucatn Peninsula'], ['The Bahamas', 'Florida', 'Georgia', 'The Carolinas', 'Virginia'], ['Southeastern United States', 'Northeastern United States', 'Southwestern Quebec'], ['Bermuda', 'New England', 'Atlantic Canada'], ['Lesser Antilles', 'Central America'], ['Texas', 'Louisiana', 'Midwestern United States'], ['Central America'], ['The Caribbean', 'Mexico', 'Texas'], ['Cuba', 'United States Gulf Coast'], ['The Caribbean', 'Central America', 'Mexico', 'United States Gulf Coast'], ['Mexico'], ['The Caribbean', 'United States East coast'], ['The Caribbean', 'Yucatn Peninsula', 'Mexico', 'South Texas'], ['Jamaica', 'Venezuela', 'Central America', 'Hispaniola', 'Mexico'], ['The Caribbean', 'United States East Coast'], ['The Bahamas', 'Florida', 'United States Gulf Coast'], ['Central America', 'Yucatn Peninsula', 'South Florida'], ['Greater Antilles', 'Bahamas', 'Eastern United States', 'Ontario'], ['The Caribbean', 'Venezuela', 'United States Gulf Coast'], ['Windward Islands', 'Jamaica', 'Mexico', 'Texas'], ['Bahamas', 'United States Gulf Coast'], ['Cuba', 'United States Gulf Coast'], ['Greater Antilles', 'Central America', 'Florida'], ['The Caribbean', 'Central America'], ['Nicaragua', 'Honduras'], ['Antilles', 'Venezuela', 'Colombia', 'United States East Coast', 'Atlantic Canada'], ['Cape Verde', 'The Caribbean', 'British Virgin Islands', 'U.S. Virgin Islands', 'Cuba', 'Florida'], ['Lesser Antilles', 'Virgin Islands', 'Puerto Rico', 'Dominican Republic', 'Turks and Caicos Islands'], ['Central America', 'United States Gulf Coast (especially Florida Panhandle)']]
15+
16+
# damages (USD($)) of hurricanes
17+
damages = ['Damages not recorded', '100M', 'Damages not recorded', '40M', '27.9M', '5M', 'Damages not recorded', '306M', '2M', '65.8M', '326M', '60.3M', '208M', '1.42B', '25.4M', 'Damages not recorded', '1.54B', '1.24B', '7.1B', '10B', '26.5B', '6.2B', '5.37B', '23.3B', '1.01B', '125B', '12B', '29.4B', '1.76B', '720M', '15.1B', '64.8B', '91.6B', '25.1B']
18+
19+
# deaths for each hurricane
20+
deaths = [90,4000,16,3103,179,184,408,682,5,1023,43,319,688,259,37,11,2068,269,318,107,65,19325,51,124,17,1836,125,87,45,133,603,138,3057,74]
21+
22+
# 1
23+
# Update Recorded Damages
24+
conversion = {"M": 1000000,
25+
"B": 1000000000}
26+
def updated_damages_fn(damages):
27+
updated_damages = []
28+
for damage in damages:
29+
if 'Damages not recorded' in damage:
30+
updated_damages.append(damage)
31+
if 'M' in damage:
32+
updated_damages.append(float(damage.strip('M'))*conversion['M'])
33+
if 'B' in damage:
34+
updated_damages.append(float(damage.strip('B'))*conversion['B'])
35+
return updated_damages
36+
37+
# test function by updating damages
38+
updated_damages = updated_damages_fn(damages)
39+
#print(updated_damages)
40+
41+
# 2
42+
# Create a Table
43+
def dict_fn(names, months, years, max_sustained_winds,updated_damages, areas_affected, deaths):
44+
dict = {}
45+
for i in range(len(names)):
46+
dict[names[i]] = {'Name': names[i], 'Month': months[i], 'Year': years[i], 'Max Sustained Wind': max_sustained_winds[i], 'Areas Affected': areas_affected[i], 'Damage': updated_damages[i], 'Deaths': deaths[i]}
47+
return dict
48+
49+
dict = dict_fn(names, months, years, max_sustained_winds,updated_damages, areas_affected, deaths)
50+
51+
print(dict)
52+
53+
#print(dict_fn(names, months, years, max_sustained_winds,updated_damages, areas_affected, deaths))
54+
55+
56+
# Create and view the hurricanes dictionary
57+
58+
# 3
59+
# Organizing by Year
60+
def year_dict(dict):
61+
hurricane_years = {}
62+
#for loop that checks if year in hurricane_years, and adds data
63+
for data in dict.values():
64+
for year, lst in hurricane_years.items():
65+
if data['Year'] == year:
66+
lst.append(data)
67+
hurricane_years.update({data['Year']: [data]})
68+
return hurricane_years
69+
70+
# create a new dictionary of hurricanes with year and key
71+
year_dict = year_dict(dict)
72+
#print(year_dict)
73+
74+
# 4
75+
# Counting Damaged Areas
76+
77+
# create dictionary of areas to store the number of hurricanes involved in
78+
79+
def areas_affecteddict(dict):
80+
total_areas_affected = []
81+
total_areas_affected_dict = {}
82+
#areas_affected_dict = defaultdict(total_areas_affected)
83+
for hurricanes in dict.values():
84+
for key,values in hurricanes.items():
85+
if key == 'Areas Affected':
86+
total_areas_affected += values
87+
for i in total_areas_affected:
88+
if i not in total_areas_affected_dict:
89+
total_areas_affected_dict[i] = 1
90+
if i in total_areas_affected_dict:
91+
total_areas_affected_dict[i] += 1
92+
return total_areas_affected_dict
93+
94+
dict_areas_affected = areas_affecteddict(dict)
95+
#print(dict_areas_affected)
96+
97+
98+
# 5
99+
# Calculating Maximum Hurricane Count
100+
def max_hurricane_count(dict_areas_affected):
101+
max = 0
102+
max_affected = ''
103+
for key, value in dict_areas_affected.items():
104+
if value > max:
105+
max = value
106+
max_affected = key
107+
return max_affected, max
108+
max_hurricane = max_hurricane_count(dict_areas_affected)
109+
#print(max_hurricane)
110+
111+
# find most frequently affected area and the number of hurricanes involved in
112+
113+
114+
# 6
115+
# Calculating the Deadliest Hurricane
116+
def deadliest_hurricane(dict):
117+
max_value = 0
118+
max = ''
119+
for i in dict.values():
120+
for key, value in i.items():
121+
if key == 'Deaths':
122+
if value > max_value:
123+
max_value = value
124+
max = i['Name']
125+
return max, max_value
126+
127+
deadliest_hurricane = deadliest_hurricane(dict)
128+
#print(deadliest_hurricane)
129+
130+
131+
# find highest mortality hurricane and the number of deaths
132+
mortality_scale = {0: 0,
133+
1: 100,
134+
2: 500,
135+
3: 1000,
136+
4: 10000}
137+
# 7
138+
# Rating Hurricanes by Mortality
139+
def hurricanes_by_mortality(dict):
140+
hurricanes_by_mortalitydict = {0: '',1: '', 2: '', 3: '',4:''}
141+
for i in dict.values():
142+
for key, value in i.items():
143+
if key == 'Deaths':
144+
if value == 0:
145+
hurricanes_by_mortalitydict[0] += ',' + i['Name']
146+
if value > 0 and value >= 100:
147+
hurricanes_by_mortalitydict[1] += ',' + i['Name']
148+
if value > 100 and value >= 500:
149+
hurricanes_by_mortalitydict[2] += ',' + i['Name']
150+
if value > 500 and value >= 1000:
151+
hurricanes_by_mortalitydict[3] += ',' + i['Name']
152+
if value > 1000 and value >= 10000:
153+
hurricanes_by_mortalitydict[4] += ',' + i['Name']
154+
return hurricanes_by_mortalitydict
155+
hurricanes_by_mortalitydict = hurricanes_by_mortality(dict)
156+
#print(hurricanes_by_mortalitydict)
157+
158+
159+
160+
161+
162+
# categorize hurricanes in new dictionary with mortality severity as key
163+
164+
165+
# 8 Calculating Hurricane Maximum Damage
166+
167+
# find highest damage inducing hurricane and its total cost
168+
def max_damage(dict):
169+
max_damage = ''
170+
cost = 0
171+
for i in dict.values():
172+
for key, value in i.items():
173+
if key == "Damage":
174+
if value == "Damages not recorded":
175+
continue
176+
if int(value) > cost:
177+
cost = value
178+
max_damage = i['Name']
179+
return max_damage, cost
180+
max_damages = max_damage(dict)
181+
#print(max_damages)
182+
183+
# 9
184+
# Rating Hurricanes by Damage
185+
damage_scale = {0: 0,
186+
1: 100000000,
187+
2: 1000000000,
188+
3: 10000000000,
189+
4: 50000000000}
190+
191+
# categorize hurricanes in new dictionary with damage severity as key
192+
def damage_scale(dict):
193+
damage_scale_dict = {0: '',
194+
1: '',
195+
2: '',
196+
3: '',
197+
4: ''}
198+
for i in dict.values():
199+
for key, value in i.items():
200+
if key == "Damage":
201+
if value == "Damages not recorded":
202+
continue
203+
if value == 0:
204+
damage_scale_dict[0] += i['Name']
205+
if value > 100000000:
206+
damage_scale_dict[1] += i['Name'] + ', '
207+
if value > 1000000000:
208+
damage_scale_dict[2] += i['Name'] + ', '
209+
if value > 10000000000:
210+
damage_scale_dict[3] += i['Name'] + ', '
211+
if value > 5000000000:
212+
damage_scale_dict[4] += i['Name'] + ', '
213+
return damage_scale_dict
214+
damage_scale = damage_scale(dict)
215+
print(damage_scale)

0 commit comments

Comments
 (0)