Practice: Earthquakes#

Jupyter Notebooks

Reminder, that on this site the Jupyter Notebooks are read-only and you can’t interact with them. Click the button above to launch an interactive version of this notebook.

  • With Binder, you get a temporary Jupyter Notebook website that opens with this notebook. Any code you write will be lost when you close the tab. Make sure to download the notebook so you can save it for later!

  • With Colab, it will open Google Colaboratory. You can save the notebook there to your Google Drive. If you don’t save to your Drive, any code you write will be lost when you close the tab. You can find the data files for this notebook below:

You will need to run all the cells of the notebook to see the output. You can do this with hitting Shift-Enter on each cell or clickin the “Run All” button above.

For this problem, we will be using the earthquakes dataset from the last lesson.

import pandas as pd

df = pd.read_csv('earthquakes.csv')
df.head() # Method to only display the first few rows
id year month day latitude longitude name magnitude
0 nc72666881 2016 7 27 37.672333 -121.619000 California 1.43
1 us20006i0y 2016 7 27 21.514600 94.572100 Burma 4.90
2 nc72666891 2016 7 27 37.576500 -118.859167 California 0.06
3 nc72666896 2016 7 27 37.595833 -118.994833 California 0.40
4 nn00553447 2016 7 27 39.377500 -119.845000 Nevada 0.30

Problem 0#

Compute the average magnitude of all the earthquakes in the dataset. Your result should be a float.

For testing purposes, store the result in a variable called ans0.

# Write your code here!

Problem 1#

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.

For testing purposes, store the result in a variable called ans1.

# Write your code here!

Problem 2#

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.

For testing purposes, store the result in a variable called ans2.

# Write your code here!

Problem 3#

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.

For testing purposes, store the result in a variable called ans3.

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?

# Write your code here!