{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idyearmonthdaylatitudelongitudenamemagnitude
0nc72666881201672737.672333-121.619000California1.43
1us20006i0y201672721.51460094.572100Burma4.90
2nc72666891201672737.576500-118.859167California0.06
3nc72666896201672737.595833-118.994833California0.40
4nn00553447201672739.377500-119.845000Nevada0.30
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idyearmonthdaylatitudelongitudenamemagnitude
3877us10006cwy201688-4.6796155.2703Papua New Guinea4.3
3897us10006cx0201688-4.2667153.6873Papua New Guinea4.1
4012us10006cxc201688-23.3895-175.0769Tonga4.6
4036us10006cxf201688-4.4296151.9396Papua New Guinea4.4
\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 }