diff --git a/Hurricane Analysis/.ipynb_checkpoints/Hurricane Analysis-checkpoint.ipynb b/Hurricane Analysis/.ipynb_checkpoints/Hurricane Analysis-checkpoint.ipynb new file mode 100644 index 0000000..9c35f42 --- /dev/null +++ b/Hurricane Analysis/.ipynb_checkpoints/Hurricane Analysis-checkpoint.ipynb @@ -0,0 +1,412 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "58875e7a", + "metadata": {}, + "source": [ + "# Hurricane Analysis" + ] + }, + { + "cell_type": "markdown", + "id": "9a2d9627", + "metadata": {}, + "source": [ + "#### Overview" + ] + }, + { + "cell_type": "markdown", + "id": "633e5dde", + "metadata": {}, + "source": [ + "This project is slightly different than others you have encountered thus far. 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." + ] + }, + { + "cell_type": "markdown", + "id": "52f01f07", + "metadata": {}, + "source": [ + "#### Project Goals" + ] + }, + { + "cell_type": "markdown", + "id": "d9d06c43", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "markdown", + "id": "7fbb9fb5", + "metadata": {}, + "source": [ + "#### Prerequisites" + ] + }, + { + "cell_type": "markdown", + "id": "4732a1e8", + "metadata": {}, + "source": [ + "In order to complete this project, you should have completed the Loops and Dictionaries sections of the [Learn Python 3 Course](https://www.codecademy.com/learn/learn-python-3). This content is also covered in the [Data Scientist Career Path](https://www.codecademy.com/learn/paths/data-science/)." + ] + }, + { + "cell_type": "markdown", + "id": "1e924903", + "metadata": {}, + "source": [ + "## Project Requirements" + ] + }, + { + "cell_type": "markdown", + "id": "35d6f74d", + "metadata": {}, + "source": [ + "1. 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 occured. \n", + "\n", + " 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 $\\ge$ 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`).\n", + " \n", + " 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\"`.\n", + " \n", + " Test your function with the data stored in `damages`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d8d3c50b", + "metadata": {}, + "outputs": [], + "source": [ + "# damages (USD($)) of hurricanes\n", + "damages = ['Damages not recorded', '100M', 'Damages not recorded', '40M',\n", + " '27.9M', '5M', 'Damages not recorded', '306M', '2M', '65.8M',\n", + " '326M', '60.3M', '208M', '1.42B', '25.4M', 'Damages not recorded',\n", + " '1.54B', '1.24B', '7.1B', '10B', '26.5B', '6.2B', '5.37B', '23.3B',\n", + " '1.01B', '125B', '12B', '29.4B', '1.76B', '720M', '15.1B', '64.8B',\n", + " '91.6B', '25.1B']\n", + "\n", + "# 1\n", + "# Update Recorded Damages\n", + "conversion = {\"M\": 1000000,\n", + " \"B\": 1000000000}\n", + "\n", + "# test function by updating damages\n" + ] + }, + { + "cell_type": "markdown", + "id": "36ac47b6", + "metadata": {}, + "source": [ + "2. Additional data collected on the `34` strongest Atlantic hurricanes are provided in a series of lists. The data includes:\n", + " - `names`: names of the hurricanes\n", + " - `months`: months in which the hurricanes occurred\n", + " - `years`: years in which the hurricanes occurred\n", + " - `max_sustained_winds`: maximum sustained winds (miles per hour) of the hurricanes\n", + " - `areas_affected`: list of different areas affected by each of the hurricanes\n", + " - `deaths`: total number of deaths caused by each of the hurricanes\n", + " \n", + " The data is organized such that the data at each index, from `0` to `33`, corresponds to the same hurricane.\n", + " \n", + " For example, `names[0]` yields the \"Cuba I\" hurricane, which occurred in `months[0]` (October) `years[0]` (1924).\n", + " \n", + " 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.\n", + " \n", + " 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}`.\n", + " \n", + " Test your function on the lists of data provided." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "641aa113", + "metadata": {}, + "outputs": [], + "source": [ + "# names of hurricanes\n", + "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']\n", + "\n", + "# months of hurricanes\n", + "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']\n", + "\n", + "# years of hurricanes\n", + "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]\n", + "\n", + "# maximum sustained winds (mph) of hurricanes\n", + "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]\n", + "\n", + "# areas affected by each hurricane\n", + "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)']]\n", + "\n", + "# damages (USD($)) of hurricanes\n", + "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']\n", + "\n", + "# deaths for each hurricane\n", + "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]\n", + "\n", + "# 2\n", + "# Create a Table\n", + "\n", + "# Create and view the hurricanes dictionary\n" + ] + }, + { + "cell_type": "markdown", + "id": "6d0a1933", + "metadata": {}, + "source": [ + "3. 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.\n", + "\n", + " 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.\n", + " \n", + " 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': 'Damage 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}]`.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "1ef2edea", + "metadata": {}, + "outputs": [], + "source": [ + "# 3\n", + "# Organizing by Year\n", + "\n", + "# create a new dictionary of hurricanes with year and key\n" + ] + }, + { + "cell_type": "markdown", + "id": "66973f77", + "metadata": {}, + "source": [ + "4. 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.\n", + "\n", + " 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.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "bff86f77", + "metadata": {}, + "outputs": [], + "source": [ + "# 4\n", + "# Counting Damaged Areas\n", + "\n", + "# create dictionary of areas to store the number of hurricanes involved in\n" + ] + }, + { + "cell_type": "markdown", + "id": "e015eeb3", + "metadata": {}, + "source": [ + "5. Write a function that finds the area affected by the most hurricanes, and how often it was hit.\n", + "\n", + " Test your function on your affected area dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "643c73f9", + "metadata": {}, + "outputs": [], + "source": [ + "# 5\n", + "# Calculating Maximum Hurricane Count\n", + "\n", + "# find most frequently affected area and the number of hurricanes involved in\n" + ] + }, + { + "cell_type": "markdown", + "id": "4c120f59", + "metadata": {}, + "source": [ + "6. Write a function that finds the hurricane that caused the greatest number of deaths, and how many deaths it caused.\n", + "\n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "ced02448", + "metadata": {}, + "outputs": [], + "source": [ + "# 6\n", + "# Calculating the Deadliest Hurricane\n", + "\n", + "# find highest mortality hurricane and the number of deaths\n" + ] + }, + { + "cell_type": "markdown", + "id": "9ddd39b0", + "metadata": {}, + "source": [ + "7. Just as hurricanes are rated by their windspeed, you want to try rating hurricanes based on other metrics.\n", + "\n", + " 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.\n", + " \n", + " ```py\n", + " mortality_scale = {0: 0,\n", + " 1: 100,\n", + " 2: 500,\n", + " 3: 1000,\n", + " 4: 10000}\n", + " ```\n", + " \n", + " 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 would have resulted in greater than `10000` deaths.\n", + " \n", + " Store the hurricanes in a new dictionary where the keys are the mortaility ratings and the values are lists containing a dictionary for each hurricane that falls into that mortality rating.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9eea4dc7", + "metadata": {}, + "outputs": [], + "source": [ + "# 7\n", + "# Rating Hurricanes by Mortality\n", + "\n", + "# categorize hurricanes in new dictionary with mortality severity as key\n" + ] + }, + { + "cell_type": "markdown", + "id": "199b0e1c", + "metadata": {}, + "source": [ + "8. Write a function that finds the hurricane that caused the greatest damage, and how costly it was.\n", + "\n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b3dc79b4", + "metadata": {}, + "outputs": [], + "source": [ + "# 8\n", + "# Calculating Hurricane Maximum Damage\n", + "\n", + "# find highest damage inducing hurricane and its total cost\n" + ] + }, + { + "cell_type": "markdown", + "id": "58d22ddc", + "metadata": {}, + "source": [ + "9. Lastly, you want to rate hurricanes according to how much damage they cause.\n", + "\n", + " 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.\n", + " ```py\n", + " damage_scale = {0: 0,\n", + " 1: 100000000,\n", + " 2: 1000000000,\n", + " 3: 10000000000,\n", + " 4: 50000000000}\n", + " ```\n", + " \n", + " 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).\n", + " \n", + " 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.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "e543f487", + "metadata": {}, + "outputs": [], + "source": [ + "# 9\n", + "# Rating Hurricanes by Damage\n", + "damage_scale = {0: 0,\n", + " 1: 100000000,\n", + " 2: 1000000000,\n", + " 3: 10000000000,\n", + " 4: 50000000000}\n", + "\n", + "# categorize hurricanes in new dictionary with damage severity as key\n" + ] + }, + { + "cell_type": "markdown", + "id": "928c5fd2", + "metadata": {}, + "source": [ + "## Solution" + ] + }, + { + "cell_type": "markdown", + "id": "252616a3", + "metadata": {}, + "source": [ + "Great work! View the **Hurricane Analysis_Solution.ipynb** file or visit [our forums](https://discuss.codecademy.com/t/hurricane-analysis-challenge-project-python/462363) 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 than ours, and that's okay! There are multiple ways to solve these projects, and you'll learn more by seeing others' code." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da8f7141", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.10.8 64-bit (microsoft store)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.8" + }, + "vscode": { + "interpreter": { + "hash": "b784193cf0f9970b27f3c12f21dbff8ed97e3cf923dc23fe210654173bc3fdd0" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Hurricane Analysis/Hurricane Analysis.ipynb b/Hurricane Analysis/Hurricane Analysis.ipynb new file mode 100644 index 0000000..3898b20 --- /dev/null +++ b/Hurricane Analysis/Hurricane Analysis.ipynb @@ -0,0 +1,599 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "58875e7a", + "metadata": {}, + "source": [ + "# Hurricane Analysis" + ] + }, + { + "cell_type": "markdown", + "id": "9a2d9627", + "metadata": {}, + "source": [ + "#### Overview" + ] + }, + { + "cell_type": "markdown", + "id": "633e5dde", + "metadata": {}, + "source": [ + "This project is slightly different than others you have encountered thus far. 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." + ] + }, + { + "cell_type": "markdown", + "id": "52f01f07", + "metadata": {}, + "source": [ + "#### Project Goals" + ] + }, + { + "cell_type": "markdown", + "id": "d9d06c43", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "markdown", + "id": "7fbb9fb5", + "metadata": {}, + "source": [ + "#### Prerequisites" + ] + }, + { + "cell_type": "markdown", + "id": "4732a1e8", + "metadata": {}, + "source": [ + "In order to complete this project, you should have completed the Loops and Dictionaries sections of the [Learn Python 3 Course](https://www.codecademy.com/learn/learn-python-3). This content is also covered in the [Data Scientist Career Path](https://www.codecademy.com/learn/paths/data-science/)." + ] + }, + { + "cell_type": "markdown", + "id": "1e924903", + "metadata": {}, + "source": [ + "## Project Requirements" + ] + }, + { + "cell_type": "markdown", + "id": "35d6f74d", + "metadata": {}, + "source": [ + "1. 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 occured. \n", + "\n", + " 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 $\\ge$ 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`).\n", + " \n", + " 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\"`.\n", + " \n", + " Test your function with the data stored in `damages`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d8d3c50b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Damages not recorded', 100000000.0, 'Damages not recorded', 40000000.0, 27900000.0, 5000000.0, 'Damages not recorded', 306000000.0, 2000000.0, 65800000.0, 326000000.0, 60300000.0, 208000000.0, 1420000000.0, 25400000.0, 'Damages not recorded', 1540000000.0, 1240000000.0, 7100000000.0, 10000000000.0, 26500000000.0, 6200000000.0, 5370000000.0, 23300000000.0, 1010000000.0, 125000000000.0, 12000000000.0, 29400000000.0, 1760000000.0, 720000000.0, 15100000000.0, 64800000000.0, 91600000000.0, 25100000000.0]\n" + ] + } + ], + "source": [ + "# damages (USD($)) of hurricanes\n", + "damages = ['Damages not recorded', '100M', 'Damages not recorded', '40M',\n", + " '27.9M', '5M', 'Damages not recorded', '306M', '2M', '65.8M',\n", + " '326M', '60.3M', '208M', '1.42B', '25.4M', 'Damages not recorded',\n", + " '1.54B', '1.24B', '7.1B', '10B', '26.5B', '6.2B', '5.37B', '23.3B',\n", + " '1.01B', '125B', '12B', '29.4B', '1.76B', '720M', '15.1B', '64.8B',\n", + " '91.6B', '25.1B']\n", + "\n", + "# 1\n", + "# Update Recorded Damages\n", + "def convert_damages_data(damages):\n", + " conversion = {\"M\": 1000000, \"B\": 1000000000}\n", + " updated_damages = []\n", + " for damage in damages:\n", + " if damage == \"Damages not recorded\":\n", + " updated_damages.append(damage)\n", + " elif \"M\" in damage:\n", + " updated_damages.append(float(damage.strip('M')) * conversion[\"M\"])\n", + " elif \"B\" in damage:\n", + " updated_damages.append(float(damage.strip('B')) * conversion[\"B\"])\n", + " return updated_damages\n", + "\n", + "# test function by updating damages\n", + "updated_damages = convert_damages_data(damages)\n", + "print(updated_damages)" + ] + }, + { + "cell_type": "markdown", + "id": "36ac47b6", + "metadata": {}, + "source": [ + "2. Additional data collected on the `34` strongest Atlantic hurricanes are provided in a series of lists. The data includes:\n", + " - `names`: names of the hurricanes\n", + " - `months`: months in which the hurricanes occurred\n", + " - `years`: years in which the hurricanes occurred\n", + " - `max_sustained_winds`: maximum sustained winds (miles per hour) of the hurricanes\n", + " - `areas_affected`: list of different areas affected by each of the hurricanes\n", + " - `deaths`: total number of deaths caused by each of the hurricanes\n", + " \n", + " The data is organized such that the data at each index, from `0` to `33`, corresponds to the same hurricane.\n", + " \n", + " For example, `names[0]` yields the \"Cuba I\" hurricane, which occurred in `months[0]` (October) `years[0]` (1924).\n", + " \n", + " 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.\n", + " \n", + " 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}`.\n", + " \n", + " Test your function on the lists of data provided." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "641aa113", + "metadata": {}, + "outputs": [], + "source": [ + "# names of hurricanes\n", + "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']\n", + "\n", + "# months of hurricanes\n", + "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']\n", + "\n", + "# years of hurricanes\n", + "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]\n", + "\n", + "# maximum sustained winds (mph) of hurricanes\n", + "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]\n", + "\n", + "# areas affected by each hurricane\n", + "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)']]\n", + "\n", + "# damages (USD($)) of hurricanes\n", + "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']\n", + "\n", + "# deaths for each hurricane\n", + "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]\n", + "\n", + "# 2\n", + "# Create a \n", + "def create_dictionary(names, months, years, max_sustained_winds, areas_affected, updated_damages, deaths):\n", + " hurricanes = {}\n", + " num_hurricanes = len(names)\n", + " for i in range(num_hurricanes):\n", + " hurricanes[names[i]] = {\n", + " \"Name\": names[i],\n", + " \"Month\": months[i],\n", + " \"Year\": years[i],\n", + " \"Max Sustained Wind\": max_sustained_winds[i],\n", + " \"Areas Affected\": areas_affected[i],\n", + " \"Damage\": updated_damages[i],\n", + " \"Deaths\": deaths[i]\n", + " }\n", + " return hurricanes\n", + "\n", + "# Create and view the hurricanes dictionary\n", + "hurricanes = create_dictionary(names, months, years, max_sustained_winds, areas_affected, updated_damages, deaths)\n", + "#print(hurricanes)" + ] + }, + { + "cell_type": "markdown", + "id": "6d0a1933", + "metadata": {}, + "source": [ + "3. 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.\n", + "\n", + " 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.\n", + " \n", + " 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': 'Damage 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}]`.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1ef2edea", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'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}]\n" + ] + } + ], + "source": [ + "# 3\n", + "# Organizing by \n", + "def create_year_dictionary(hurricanes):\n", + " hurricanes_by_year = {}\n", + " for hurricane in hurricanes.values():\n", + " year = hurricane['Year']\n", + " if year not in hurricanes_by_year:\n", + " hurricanes_by_year[year] = [hurricane]\n", + " else:\n", + " hurricanes_by_year[year].append(hurricane)\n", + " return hurricanes_by_year\n", + "\n", + "# create a new dictionary of hurricanes with year and key\n", + "hurricanes_by_year = create_year_dictionary(hurricanes)\n", + "print(hurricanes_by_year[1932])" + ] + }, + { + "cell_type": "markdown", + "id": "66973f77", + "metadata": {}, + "source": [ + "4. 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.\n", + "\n", + " 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.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "bff86f77", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Central America': 9, 'Mexico': 7, 'Cuba': 6, 'Florida': 6, 'The Bahamas': 7, 'Lesser Antilles': 4, 'United States East Coast': 3, 'Atlantic Canada': 3, 'Northeastern United States': 2, 'Jamaica': 4, 'Cayman Islands': 1, 'Bermuda': 2, 'Texas': 4, 'Tamaulipas': 1, 'Yucatn Peninsula': 3, 'Georgia': 1, 'The Carolinas': 1, 'Virginia': 1, 'Southeastern United States': 1, 'Southwestern Quebec': 1, 'New England': 1, 'Louisiana': 1, 'Midwestern United States': 1, 'The Caribbean': 8, 'United States Gulf Coast': 6, 'United States East coast': 1, 'South Texas': 1, 'Venezuela': 3, 'Hispaniola': 1, 'South Florida': 1, 'Greater Antilles': 2, 'Bahamas': 2, 'Eastern United States': 1, 'Ontario': 1, 'Windward Islands': 1, 'Nicaragua': 1, 'Honduras': 1, 'Antilles': 1, 'Colombia': 1, 'Cape Verde': 1, 'British Virgin Islands': 1, 'U.S. Virgin Islands': 1, 'Virgin Islands': 1, 'Puerto Rico': 1, 'Dominican Republic': 1, 'Turks and Caicos Islands': 1, 'United States Gulf Coast (especially Florida Panhandle)': 1}\n" + ] + } + ], + "source": [ + "# 4\n", + "# Counting Damaged Areas\n", + "def count_affected_areas(hurricanes):\n", + " affected_areas_count = {}\n", + " for hurricane in hurricanes.values():\n", + " for area in hurricane['Areas Affected']:\n", + " if area not in affected_areas_count:\n", + " affected_areas_count[area] = 1\n", + " else:\n", + " affected_areas_count[area] += 1\n", + " return affected_areas_count\n", + "\n", + "# create dictionary of areas to store the number of hurricanes involved in\n", + "affected_areas_count = count_affected_areas(hurricanes)\n", + "print(affected_areas_count)\n" + ] + }, + { + "cell_type": "markdown", + "id": "e015eeb3", + "metadata": {}, + "source": [ + "5. Write a function that finds the area affected by the most hurricanes, and how often it was hit.\n", + "\n", + " Test your function on your affected area dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "643c73f9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Central America 9\n" + ] + } + ], + "source": [ + "# 5\n", + "# Calculating Maximum Hurricane \n", + "def most_affected_area(affected_areas_count):\n", + " max_area = None\n", + " max_count = 0\n", + " for area, count in affected_areas_count.items():\n", + " if count > max_count:\n", + " max_area = area\n", + " max_count = count\n", + " return max_area, max_count\n", + "\n", + "# find most frequently affected area and the number of hurricanes involved in\n", + "max_area, max_count = most_affected_area(affected_areas_count)\n", + "print(max_area, max_count)" + ] + }, + { + "cell_type": "markdown", + "id": "4c120f59", + "metadata": {}, + "source": [ + "6. Write a function that finds the hurricane that caused the greatest number of deaths, and how many deaths it caused.\n", + "\n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "ced02448", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mitch 19325\n" + ] + } + ], + "source": [ + "# 6\n", + "# Calculating the Deadliest \n", + "def highest_mortality(hurricanes):\n", + " max_deaths = 0\n", + " deadliest_hurricane = None\n", + " for hurricane in hurricanes.values():\n", + " if hurricane['Deaths'] > max_deaths:\n", + " max_deaths = hurricane['Deaths']\n", + " deadliest_hurricane = hurricane['Name']\n", + " return deadliest_hurricane, max_deaths\n", + "\n", + "# find highest mortality hurricane and the number of deaths\n", + "deadliest_hurricane, max_deaths = highest_mortality(hurricanes)\n", + "print(deadliest_hurricane, max_deaths)" + ] + }, + { + "cell_type": "markdown", + "id": "9ddd39b0", + "metadata": {}, + "source": [ + "7. Just as hurricanes are rated by their windspeed, you want to try rating hurricanes based on other metrics.\n", + "\n", + " 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.\n", + " \n", + " ```py\n", + " mortality_scale = {0: 0,\n", + " 1: 100,\n", + " 2: 500,\n", + " 3: 1000,\n", + " 4: 10000}\n", + " ```\n", + " \n", + " 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 would have resulted in greater than `10000` deaths.\n", + " \n", + " Store the hurricanes in a new dictionary where the keys are the mortaility ratings and the values are lists containing a dictionary for each hurricane that falls into that mortality rating.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "9eea4dc7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'Name': 'Mitch', 'Month': 'October', 'Year': 1998, 'Max Sustained Wind': 180, 'Areas Affected': ['Central America', 'Yucatn Peninsula', 'South Florida'], 'Damage': 6200000000.0, 'Deaths': 19325}]\n" + ] + } + ], + "source": [ + "# 7\n", + "# Rating Hurricanes by Mortality\n", + "def categorize_by_mortality(hurricanes):\n", + " mortality_scale = {0: 0, 1: 100, 2: 500, 3: 1000, 4: 10000}\n", + " hurricanes_by_mortality = {0: [], 1: [], 2: [], 3: [], 4: [], 5: []}\n", + " \n", + " for hurricane in hurricanes.values():\n", + " deaths = hurricane['Deaths']\n", + " if deaths <= mortality_scale[0]:\n", + " hurricanes_by_mortality[0].append(hurricane)\n", + " elif deaths <= mortality_scale[1]:\n", + " hurricanes_by_mortality[1].append(hurricane)\n", + " elif deaths <= mortality_scale[2]:\n", + " hurricanes_by_mortality[2].append(hurricane)\n", + " elif deaths <= mortality_scale[3]:\n", + " hurricanes_by_mortality[3].append(hurricane)\n", + " elif deaths <= mortality_scale[4]:\n", + " hurricanes_by_mortality[4].append(hurricane)\n", + " else:\n", + " hurricanes_by_mortality[5].append(hurricane)\n", + " return hurricanes_by_mortality\n", + " \n", + "# categorize hurricanes in new dictionary with mortality severity as key\n", + "hurricanes_by_mortality = categorize_by_mortality(hurricanes)\n", + "print(hurricanes_by_mortality[5])" + ] + }, + { + "cell_type": "markdown", + "id": "199b0e1c", + "metadata": {}, + "source": [ + "8. Write a function that finds the hurricane that caused the greatest damage, and how costly it was.\n", + "\n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "b3dc79b4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Katrina 125000000000.0\n" + ] + } + ], + "source": [ + "# 8\n", + "# Calculating Hurricane Maximum \n", + "def highest_damage(hurricanes):\n", + " max_damage = 0\n", + " costliest_hurricane = None\n", + " for hurricane in hurricanes.values():\n", + " damage = hurricane['Damage']\n", + " if damage != \"Damages not recorded\" and damage > max_damage:\n", + " max_damage = damage\n", + " costliest_hurricane = hurricane['Name']\n", + " return costliest_hurricane, max_damage\n", + "\n", + "# find highest damage inducing hurricane and its total cost\n", + "costliest_hurricane, max_damage = highest_damage(hurricanes)\n", + "print(costliest_hurricane, max_damage)" + ] + }, + { + "cell_type": "markdown", + "id": "58d22ddc", + "metadata": {}, + "source": [ + "9. Lastly, you want to rate hurricanes according to how much damage they cause.\n", + "\n", + " 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.\n", + " ```py\n", + " damage_scale = {0: 0,\n", + " 1: 100000000,\n", + " 2: 1000000000,\n", + " 3: 10000000000,\n", + " 4: 50000000000}\n", + " ```\n", + " \n", + " 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).\n", + " \n", + " 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.\n", + " \n", + " Test your function on your hurricane dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "e543f487", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'Name': 'Katrina', 'Month': 'August', 'Year': 2005, 'Max Sustained Wind': 175, 'Areas Affected': ['Bahamas', 'United States Gulf Coast'], 'Damage': 125000000000.0, 'Deaths': 1836}, {'Name': 'Irma', 'Month': 'September', 'Year': 2017, 'Max Sustained Wind': 180, 'Areas Affected': ['Cape Verde', 'The Caribbean', 'British Virgin Islands', 'U.S. Virgin Islands', 'Cuba', 'Florida'], 'Damage': 64800000000.0, 'Deaths': 138}, {'Name': 'Maria', 'Month': 'September', 'Year': 2017, 'Max Sustained Wind': 175, 'Areas Affected': ['Lesser Antilles', 'Virgin Islands', 'Puerto Rico', 'Dominican Republic', 'Turks and Caicos Islands'], 'Damage': 91600000000.0, 'Deaths': 3057}]\n" + ] + } + ], + "source": [ + "# 9\n", + "# Rating Hurricanes by Damage\n", + "def categorize_by_damage(hurricanes):\n", + " \"\"\"Categorize hurricanes by damage and return a dictionary.\"\"\"\n", + " damage_scale = {0: 0,\n", + " 1: 100000000,\n", + " 2: 1000000000,\n", + " 3: 10000000000,\n", + " 4: 50000000000}\n", + " hurricanes_by_damage = {0:[], 1:[], 2:[], 3:[], 4:[], 5:[]}\n", + " for cane in hurricanes:\n", + " total_damage = hurricanes[cane]['Damage']\n", + " if total_damage == \"Damages not recorded\":\n", + " hurricanes_by_damage[0].append(hurricanes[cane])\n", + " elif total_damage == damage_scale[0]:\n", + " hurricanes_by_damage[0].append(hurricanes[cane])\n", + " elif total_damage > damage_scale[0] and total_damage <= damage_scale[1]:\n", + " hurricanes_by_damage[1].append(hurricanes[cane])\n", + " elif total_damage > damage_scale[1] and total_damage <= damage_scale[2]:\n", + " hurricanes_by_damage[2].append(hurricanes[cane])\n", + " elif total_damage > damage_scale[2] and total_damage <= damage_scale[3]:\n", + " hurricanes_by_damage[3].append(hurricanes[cane])\n", + " elif total_damage > damage_scale[3] and total_damage <= damage_scale[4]:\n", + " hurricanes_by_damage[4].append(hurricanes[cane])\n", + " elif total_damage > damage_scale[4]:\n", + " hurricanes_by_damage[5].append(hurricanes[cane])\n", + " return hurricanes_by_damage\n", + "\n", + "# categorize hurricanes in new dictionary with damage severity as key\n", + "hurricanes_by_damage = categorize_by_damage(hurricanes)\n", + "print(hurricanes_by_damage[5])\n" + ] + }, + { + "cell_type": "markdown", + "id": "928c5fd2", + "metadata": {}, + "source": [ + "## Solution" + ] + }, + { + "cell_type": "markdown", + "id": "252616a3", + "metadata": {}, + "source": [ + "Great work! View the **Hurricane Analysis_Solution.ipynb** file or visit [our forums](https://discuss.codecademy.com/t/hurricane-analysis-challenge-project-python/462363) 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 than ours, and that's okay! There are multiple ways to solve these projects, and you'll learn more by seeing others' code." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da8f7141", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "vscode": { + "interpreter": { + "hash": "b784193cf0f9970b27f3c12f21dbff8ed97e3cf923dc23fe210654173bc3fdd0" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}