{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Earthquakes"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"For this problem, we will be using the earthquakes dataset from the last lesson."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" year | \n",
" month | \n",
" day | \n",
" latitude | \n",
" longitude | \n",
" name | \n",
" magnitude | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" nc72666881 | \n",
" 2016 | \n",
" 7 | \n",
" 27 | \n",
" 37.672333 | \n",
" -121.619000 | \n",
" California | \n",
" 1.43 | \n",
"
\n",
" \n",
" | 1 | \n",
" us20006i0y | \n",
" 2016 | \n",
" 7 | \n",
" 27 | \n",
" 21.514600 | \n",
" 94.572100 | \n",
" Burma | \n",
" 4.90 | \n",
"
\n",
" \n",
" | 2 | \n",
" nc72666891 | \n",
" 2016 | \n",
" 7 | \n",
" 27 | \n",
" 37.576500 | \n",
" -118.859167 | \n",
" California | \n",
" 0.06 | \n",
"
\n",
" \n",
" | 3 | \n",
" nc72666896 | \n",
" 2016 | \n",
" 7 | \n",
" 27 | \n",
" 37.595833 | \n",
" -118.994833 | \n",
" California | \n",
" 0.40 | \n",
"
\n",
" \n",
" | 4 | \n",
" nn00553447 | \n",
" 2016 | \n",
" 7 | \n",
" 27 | \n",
" 39.377500 | \n",
" -119.845000 | \n",
" Nevada | \n",
" 0.30 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" id year month day latitude longitude name magnitude\n",
"0 nc72666881 2016 7 27 37.672333 -121.619000 California 1.43\n",
"1 us20006i0y 2016 7 27 21.514600 94.572100 Burma 4.90\n",
"2 nc72666891 2016 7 27 37.576500 -118.859167 California 0.06\n",
"3 nc72666896 2016 7 27 37.595833 -118.994833 California 0.40\n",
"4 nn00553447 2016 7 27 39.377500 -119.845000 Nevada 0.30"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"# Make sure to update this to the correct file path!\n",
"df = pd.read_csv('earthquakes.csv')\n",
"df.head() # Method to only display the first few rows"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 1\n",
"Compute the average magnitude of all the earthquakes in the dataset. Your result should be a `float`."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.float64(1.512941386704789)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your answer here!"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 2\n",
"Compute the number of earthquakes that have a magnitude greater than or equal to the average magnitude earthquake. `DataFrames` also support the `len` function to tell you the number of rows in it. Your result should be an `int`.\n"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {},
"outputs": [],
"source": [
"# Your answer here!"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 3\n",
"Find the subset of all the earthquakes that happened on the 8th day of the month in either Tonga or Papua New Guinea. Your result should be a `DataFrame`."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" year | \n",
" month | \n",
" day | \n",
" latitude | \n",
" longitude | \n",
" name | \n",
" magnitude | \n",
"
\n",
" \n",
" \n",
" \n",
" | 3877 | \n",
" us10006cwy | \n",
" 2016 | \n",
" 8 | \n",
" 8 | \n",
" -4.6796 | \n",
" 155.2703 | \n",
" Papua New Guinea | \n",
" 4.3 | \n",
"
\n",
" \n",
" | 3897 | \n",
" us10006cx0 | \n",
" 2016 | \n",
" 8 | \n",
" 8 | \n",
" -4.2667 | \n",
" 153.6873 | \n",
" Papua New Guinea | \n",
" 4.1 | \n",
"
\n",
" \n",
" | 4012 | \n",
" us10006cxc | \n",
" 2016 | \n",
" 8 | \n",
" 8 | \n",
" -23.3895 | \n",
" -175.0769 | \n",
" Tonga | \n",
" 4.6 | \n",
"
\n",
" \n",
" | 4036 | \n",
" us10006cxf | \n",
" 2016 | \n",
" 8 | \n",
" 8 | \n",
" -4.4296 | \n",
" 151.9396 | \n",
" Papua New Guinea | \n",
" 4.4 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" id year month day latitude longitude name \\\n",
"3877 us10006cwy 2016 8 8 -4.6796 155.2703 Papua New Guinea \n",
"3897 us10006cx0 2016 8 8 -4.2667 153.6873 Papua New Guinea \n",
"4012 us10006cxc 2016 8 8 -23.3895 -175.0769 Tonga \n",
"4036 us10006cxf 2016 8 8 -4.4296 151.9396 Papua New Guinea \n",
"\n",
" magnitude \n",
"3877 4.3 \n",
"3897 4.1 \n",
"4012 4.6 \n",
"4036 4.4 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your answer here!"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 4\n",
"Find the row that corresponds to the location that has the largest earthquake on record. Your result should be a `Series` that represents that row. If there are multiple locations with the largest earthquake, you should return the first row.\n",
"\n",
"*Hint: It probably won't work to try to mask this by comparing magnitudes to the largest earthquake (since a mask won't necessarily only have a single value `True`). Is there a method that tells you the index of the largest value of a `Series`?*"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {},
"outputs": [],
"source": [
"# Your answer here!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}