Hurricane Analysis Challenge Project (Python)

Hello Everyone my code below:

# names of hurricanes
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']

# months of hurricanes
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']

# years of hurricanes
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]

# maximum sustained winds (mph) of hurricanes
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]

# areas affected by each hurricane
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)']]

# damages (USD($)) of hurricanes
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']

# deaths for each hurricane
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]

# write your update damages function here:
def update_function(damages):
    update_damages = []
    for i in damages:
        if i == 'Damages not recorded':
            #update_damages.append(i)
            update_damages.append(0)
        elif 'M' in i:
            value = i.strip('M')
            value = float(value)
            update_damages.append(value*1000000)
        else:
            value = i.strip('B')
            value = float(value)
            update_damages.append(value*1000000000)
    return update_damages
#print(update_function(damages))

# write your construct hurricane dictionary function here:
def cr_dic():
    H_data ={}
    j = 0
    for i in names:
        H_data[i] = {'Name': i, 'Months': months[j], 'Year': years[j],'Max Sustained Winds' :max_sustained_winds[j], 'Areas Affected':areas_affected[j], 'Damage': damages[j], 'Deaths' : deaths[j]}
        j += 1
    return H_data#
#print(cr_dic())

# write your construct hurricane by year dictionary function here:
def cr_dt():
    H_data_year ={}
    j = 0
    for i in years:
        H_data_year[i] = {}
        #H_data_year[i] = {'Name': names[j], 'Months': month 
        H_data_year[i]['Month'] = months[j]
        H_data_year[i]['Year'] = years[j]
        H_data_year[i]['Max Sustained Winds'] = max_sustained_winds[j]
        H_data_year[i]['Areas Affected'] = areas_affected[j]
        H_data_year[i]['Damage'] = damages[j]
        H_data_year[i]['Deaths'] = deaths[j]
        j += 1
    return H_data_year
#print(cr_dt())                
# write your count affected areas function here:
def c_aff():
    H_data_aff = {}
    areas_all =[]
    for i in range(len(areas_affected)):
        areas_all += areas_affected[i]
    for i in areas_all:
        H_data_aff[i] = areas_all.count(i)
    return H_data_aff
#print(c_aff())
# write your find most affected area function here:
def m_aff():
    new_ls = c_aff()
    new_ls_2 = [ ]
    for i in new_ls:
        new_ls_2.append([new_ls.get(i), i])
    new_ls_2.sort()
    print('The most affected area is {} by {} times.'.format( new_ls_2[-1][1],  new_ls_2[-1][0]))
#m_aff()
# write your greatest number of deaths function here:
def d_aff():
    new_ls = list(zip(deaths,names))
    new_ls.sort()
    print('The Huracan that cause the major number of deaths was {} by {} deaths.'.format( new_ls[-1][1],  new_ls[-1][0]))
#d_aff()
# write your catgeorize by mortality function here:
def mor():
    hurricanes_by_mortality = {0:[],1:[],2:[],3:[],4:[],5:[]}
    for i in range(len(deaths)):
        if deaths[i] == 0 :
           hurricanes_by_mortality[0].append(names[i])
        elif deaths[i] <= 100:
           hurricanes_by_mortality[1].append(names[i])
        elif deaths[i] <= 500:
            hurricanes_by_mortality[2].append(names[i])
        elif deaths[i] <= 1000:
            hurricanes_by_mortality[3].append(names[i])
        elif deaths[i] <= 10000:
            hurricanes_by_mortality[4].append(names[i])
        elif deaths[i] > 10000:
            hurricanes_by_mortality[5].append(names[i])
    print(hurricanes_by_mortality)
#mor()            
# write your greatest damage function here:
def dam_aff():
    update_dam = update_function(damages)
    new_ls = list(zip(update_dam,names))
    new_ls.sort()
    print('The greaest damge was cause by {} by {} dollars.'.format( new_ls[-1][1],  new_ls[-1][0]))
#dam_aff()
# write your catgeorize by damage function here:
def dam():
    update_dam = update_function(damages)
    hurricanes_by_damage = {0:[],1:[],2:[],3:[],4:[],5:[]}
    for i in range(len(deaths)):
        #print(update_dam[i])
        if update_dam[i] == 0 :
           hurricanes_by_damage[0].append(names[i])
        elif update_dam[i] <= 100000000:
           hurricanes_by_damage[1].append(names[i])
        elif update_dam[i] <= 10000000000:
            hurricanes_by_damage[2].append(names[i])
        elif update_dam[i] <= 10000000000:
            hurricanes_by_damage[3].append(names[i])
        elif update_dam[i] <= 50000000000:
            hurricanes_by_damage[4].append(names[i])
        elif update_dam[i] > 50000000000:
            hurricanes_by_damage[5].append(names[i])
    print(hurricanes_by_damage)
dam()

Hi @beta8815711983, yes! I started coding from scratch and I agree that this particular challenge is really difficult as it gives less instructions and hints than the previous ones.

I have also noticed that it requires some additional knowledge that was not covered in the Dictionaries module (such as the possibility of using .append() with dictionaries - maybe it’s obvious, but for me, it was not).

I initially got stuck at p.3 and spent several hours figuring it out. Eventually, looking and analyzing others’ solutions in this forum topic helped me move forward, so I could solve the rest of the challenge myself. Just be patient and don’t give up :raised_hands: :muscle:

Since, there are two values for 1932. Im getting the second one in the output. Where am i going wrong?

names of hurricanes

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’]

months of hurricanes

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’]

years of hurricanes

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]

maximum sustained winds (mph) of hurricanes

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]

areas affected by each hurricane

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)’]]

damages (USD($)) of hurricanes

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’]

deaths for each hurricane

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]

updated_damages =

for damage in damages:

if ‘’ in damage.split(‘M’):

updated_damages.append(float(damage.split('M')[0]) * 10**6)

elif ‘’ in damage.split(‘B’):

updated_damages.append(float(damage.split('B')[0]) * 10**9)

else:

updated_damages.append('Damages not recorded')

print(updated_damages)

def hurricane_dict(names, months, years, max_sustained_winds, areas_affected, damages, deaths):

hurricanes = {}

for index in range(len(names)):

hurricanes[names[index]] = {"Name": names[index], "Month": months[index], "Year": years[index], "Max Sustained Wind": max_sustained_winds[index], "Areas Affected": areas_affected[index], "Damage": updated_damages[index], "Deaths": deaths[index]}

return hurricanes

hurricanes_data = hurricane_dict(names, months, years, max_sustained_winds, areas_affected, damages, deaths)

def hurricane_dict_years(hurricanes_dict):

dict_years ={}

for i in range(len(names)):

dict_years[years[i]] = hurricanes_dict[names[i]]

return dict_years

hurricane_data_years = hurricane_dict_years(hurricanes_data)

Please check the following FAQ which covers amongst other things how to format code on the forums (Python without indentation is hard to understand so please use formatted code in the future). For code of this length I’d suggest using a gist or pastebin (or something along those lines).

Remember that dictionary keys should be unique, you can’t have two different key,value pairs. If you check for what happens in this case-

test_dict = {}
test_dict['a'] = 20
test_dict['b'] = 30
test_dict['a'] = 40
print(test_dict)
OUT: {'a': 40, 'b': 30}

You may need to adapt your code to deal with this.

Hi @tgrtim, Thanks for your input. Will refer FAQ and follow the guidelines. I’m a novice in this field. Apologies for the inconvenience.

However, I understood your point. I’m facing the same issue, as there are two entries of ‘1932’ in the input field. How do i get the mapping right?

I’m not sure if the hint covers it or not but you may have to add these items to a data type that supports multiple elements such as a list or another dictionary. How you implement this is up to you (e.g. I suppose you could alter the key name somewhat but I get the impression the data should be accessible by year alone).

Here is my code. Any comment or advice would be appreciated! :slight_smile:

Hurricane Dictionary Project

Just finished this project! Definitely an interesting exercise in tackling topic and using online resources to learn extra bits about how to code specific tasks.

Would love to get some feedback on coding and style. Any bad habits I’m showing or things I could have done to clean up my code a bit?

File is called Hurricane Data Analysis.ipynb

Hello guys,
here is my code. Please leave a feedback.
Thanks!
PS: To be honest, the challenge was pretty tough!

Regards

Maxim

https://github.com/kiesel24/Data-Structure-Hurricans.git

This was definitely a challenge for me, but I’m super happy to have completed it! Definitely thought about giving up at some point, but took it one problem at a time :slight_smile:. Feedback would be greatly appreciated!

Here is my code guys!

Hi everyone,

I would like to complete this project on my own computer but I feel a bit lost on how to get started. I read the documentation provided in the challenge, but this documentation refers on how to download everything we will need (python, jupyeter notebook, miniconda, etc.) I’ve downloaded all of these for the previous challenge, but I would like help on how to get started. Do I use the jupyter notebook?

Could you kindly share the steps you take to complete your python projects on your own computers? Or some documentation that helped you ?

There’s quite a lot to go into so I think your best option is looking for some kind of online guidance to help.

Something like the following might be a good place to start (but there are numerous other options if you search around)-

Start small and get a script to just output text and such before you start on this specific project.

In the longer term you will probably want to look into a code editor/IDE (basically a text editor designed with additional tools to help with programing).

2 Likes

Hi guys! Here is my solution to the project. This was a great practice regarding python’s dictionaries, it was challenging enough and I am super satisfied that I managed to complete it!
Any feedback is welcome! :slight_smile:

Hey Everyone!
I struggle for a little bit but did it! Great training and was quite fun checking documentation and solutions!
https://github.com/tfvramos/CodeTraining

Here’s my code! I used Jupyter Notebook to write this off-platform. I appreciate whatever constructive feedback I receive.

One thing I was wondering about was this: the instructions say to “create a function,” but I used for loops over and over again. I know a loop is not a function, but I was not sure if using for loops without defining a function achieved the task. I’ll look at some others’ work to see some more examples.

Edit: Okay, thanks for the ideas, everyone! I’m writing these as proper functions.

Hurricanes Analysis