Hurricane Python Dictionary Analysis Project is a project from Codecademy at the end of the Python Dictionary module. The project overview, goals and questions to look at are below while my responses and suggested solutions are contained within this repository.
PYTHON FUNDAMENTALS FOR DATA SCIENCE (PART II) Hurricane Analysis Overview This project is slightly different than others you have encountered thus far on Codecademy. Instead of a step-by-step tutorial, this project contains a series of open-ended requirements which describe the project you’ll be building. There are many possible ways to correctly fulfill all of these requirements, and you should expect to use the internet, Codecademy, and other resources when you encounter a problem that you cannot easily solve.
Project Goals You will work to write several functions that organize and manipulate data about Category 5 Hurricanes, the strongest hurricanes as rated by their wind speed. Each one of these functions will use a number of parameters, conditionals, lists, dictionaries, string manipulation, and return statements.
Setup Instructions If you choose to do this project on your computer instead of Codecademy, you can download what you’ll need by clicking the “Download” button below. If you need help setting up your computer, be sure to check out our setup guide.
Tasks 11/11 Complete Mark the tasks as complete by checking them off Prerequisites 1. In order to complete this project, you should have completed the Loops and Dictionaries sections of the Learn Python 3 Course. This content is also covered in the Data Scientist Career Path.
Project Requirements 2. Hurricanes, also known as cyclones or typhoons, are one of the most powerful forces of nature on Earth. Due to climate change caused by human activity, the number and intensity of hurricanes has risen, calling for better preparation by the many communities that are devastated by them. As a concerned environmentalist, you want to look at data about the most powerful hurricanes that have occurred.
Begin by looking at the damages list. The list contains strings representing the total cost in USD($) caused by 34 category 5 hurricanes (wind speeds ≥ 157 mph (252 km/h )) in the Atlantic region. For some of the hurricanes, damage data was not recorded ("Damages not recorded"), while the rest are written in the format "Prefix-B/M", where B stands for billions (1000000000) and M stands for millions (1000000).
Write a function that returns a new list of updated damages where the recorded data is converted to float values and the missing data is retained as "Damages not recorded".
Test your function with the data stored in damages.
Stuck? Get a hint 3. Additional data collected on the 34 strongest Atlantic hurricanes are provided in a series of lists. The data includes:
names: names of the hurricanes months: months in which the hurricanes occurred years: years in which the hurricanes occurred max_sustained_winds: maximum sustained winds (miles per hour) of the hurricanes areas_affected: list of different areas affected by each of the hurricanes deaths: total number of deaths caused by each of the hurricanes The data is organized such that the data at each index, from 0 to 33, corresponds to the same hurricane.
For example, names[0] yields the “Cuba I” hurricane, which ouccred in months[0] (October) years[0] (1924).
Write a function that constructs a dictionary made out of the lists, where the keys of the dictionary are the names of the hurricanes, and the values are dictionaries themselves containing a key for each piece of data (Name, Month, Year,Max Sustained Wind, Areas Affected, Damage, Death) about the hurricane.
Thus the key "Cuba I" would have the value: {'Name': 'Cuba I', 'Month': 'October', 'Year': 1924, 'Max Sustained Wind': 165, 'Areas Affected': ['Central America', 'Mexico', 'Cuba', 'Florida', 'The Bahamas'], 'Damage': 'Damages not recorded', 'Deaths': 90}.
Test your function on the lists of data provided.
Stuck? Get a hint 4. In addition to organizing the hurricanes in a dictionary with names as the key, you want to be able to organize the hurricanes by year.
Write a function that converts the current dictionary of hurricanes to a new dictionary, where the keys are years and the values are lists containing a dictionary for each hurricane that occurred in that year.
For example, the key 1932 would yield the value: [{'Name': 'Bahamas', 'Month': 'September', 'Year': 1932, 'Max Sustained Wind': 160, 'Areas Affected': ['The Bahamas', 'Northeastern United States'], 'Damage': 'Damages not recorded', 'Deaths': 16}, {'Name': 'Cuba II', 'Month': 'November', 'Year': 1932, 'Max Sustained Wind': 175, 'Areas Affected': ['Lesser Antilles', 'Jamaica', 'Cayman Islands', 'Cuba', 'The Bahamas', 'Bermuda'], 'Damage': 40000000.0, 'Deaths': 3103}].
Test your function on your hurricane dictionary.
Stuck? Get a hint 5. You believe that knowing how often each of the areas of the Atlantic are affected by these strong hurricanes is important for making preparations for future hurricanes.
Write a function that counts how often each area is listed as an affected area of a hurricane. Store and return the results in a dictionary where the keys are the affected areas and the values are counts of how many times the areas were affected.
Test your function on your hurricane dictionary.
Stuck? Get a hint 6. Write a function that finds the area affected by the most hurricanes, and how often it was hit.
Test your function on your affected area dictionary.
Stuck? Get a hint 7. Write a function that finds the hurricane that caused the greatest number of deaths, and how many deaths it caused.
Test your function on your hurricane dictionary.
Stuck? Get a hint 8. Just as hurricanes are rated by their windspeed, you want to try rating hurricanes based on other metrics.
Write a function that rates hurricanes on a mortality scale according to the following ratings, where the key is the rating and the value is the upper bound of deaths for that rating.
mortality_scale = {0: 0, 1: 100, 2: 500, 3: 1000, 4: 10000} For example, a hurricane with a 1 mortality rating would have resulted in greater than 0 but less than or equal to 100 deaths. A hurricane with a 5 mortality rating would have resulted in greater than 10000 deaths.
Store the hurricanes in a new dictionary where the keys are mortality ratings and the values are lists containing a dictionary for each hurricane that falls into that mortality rating.
Test your function on your hurricane dictionary.
Hint Our function initializes a new dictionary with mortality ratings as the keys and empty lists as the values.
hurricanes_by_mortality = {0:[],1:[],2:[],3:[],4:[],5:[]} We then iterate through each hurricane in our dictionary, find the deaths caused by that hurricane, and compare the deaths to the lower and upper bound for each of the mortality ratings. If the death count falls above the lower bound and is less than or equal to the upper bound of deaths for a rating, the hurricane is appended to the list of the appropriate rating in hurricanes_by_mortality.
Write a function that finds the hurricane that caused the greatest damage, and how costly it was.
Test your function on your hurricane dictionary.
Hint Our function assumes one hurricane to be the most costly, and initializes how costly it was:
max_damage_cane = 'Cuba I' max_damage = 0 We then iterate through each hurricane in our hurricane dictionary and first check to see if any damage was recorded. If we find that the damage value is "Damages not recorded", we do nothing. If a damage was recorded, we compare the damage to max_damage. If max_damage is less than the damage for a hurricane, max_damage_cane is updated to the current hurricane and max_damage is updated to damage for that hurricane.
Lastly, you want to rate hurricanes according to how much damage they cause.
Write a function that rates hurricanes on a damage scale according to the following ratings, where the key is the rating and the value is the upper bound of damage for that rating.
damage_scale = {0: 0, 1: 100000000, 2: 1000000000, 3: 10000000000, 4: 50000000000} For example, a hurricane with a 1 damage rating would have resulted in damages greater than 0 USD but less than or equal to 100000000 USD. A hurricane with a 5 damage rating would have resulted in damages greater than 50000000000 USD (talk about a lot of money).
Store the hurricanes in a new dictionary where the keys are damage ratings and the values are lists containing a dictionary for each hurricane that falls into that damage rating.
Test your function on your hurricane dictionary.
Hint Our function initializes a new dictionary with damage ratings as the keys and empty lists as the values.
hurricanes_by_damage = {0:[],1:[],2:[],3:[],4:[],5:[]} We then iterate through each hurricane in our dictionary, find the damage caused by that hurricane, and compare the damage to the lower and upper bound for each of the damage ratings. If the damages fall above the lower bound and are less than or equal to the upper bound of damages for a rating, the hurricane is appended to the list of the appropriate rating in hurricanes_by_damage.
Solution 11. Great work! Visit our forums to compare your project to our sample solution code. You can also learn how to host your own solution on GitHub so you can share it with other learners! Your solution might look different from ours, and that’s okay! There are multiple ways to solve these projects, and you’ll learn more by seeing others’ code.