Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python / Data Programming Data: Problem: Code: Average Magnitude Data For this problem, we will be using a dataset containing information about earthquakes around the

Python / Data Programming
Data:
image text in transcribed
Problem:
image text in transcribed
Code:
image text in transcribed
Average Magnitude Data For this problem, we will be using a dataset containing information about earthquakes around the world. The dataset looks like the following (but it has more rows). magnitude 1.43 id year month day latitude nc 72666881 2016 7 27 us20006i0y 2016 7 27 nc72666891 2016 7 27 nc 72666896 2016 7 27 nn00553447 2016 7 27 earthquakes longitude name 37.6723333 -121.619 California 21.5146 94.5721 Burma 37.5765 -118.85916670000000 California 37.5958333 -118.99483330000000 California 39.3775 - 119.845 Nevada 4.9 0.06 0.4 0.3 The dataset is stored in a shared location on Ed with the path /course/lessons/earthquakes.csv Problem Write a function named average_magnitude that takes a parameter data that stores this earthquakes dataset, represented as a list of dictionaries, and a year as a parameters. Your function should return the average magnitude of all earthquakes that happened in the given year. If there are no earthquakes for the given year, your function should return None. For example, if we called average_magnitude (data, 2016), where data stored a list of dictionaries representing the five rows in the image above, it would return 1.418. You should not assume the dataset passed has the exact same values or the number of rows as the one shown above. For example, you should not assume the dataset has more than one row. However, you should assume the dataset provided will have all of the columns provided for any row in the dataset (we sometimes call the set of columns of a CSV its schema). Note that you do not need to worry about how to parse the data from the CSV format to the list of dictionaries. We implemented this functionality in cse163_utils.py and already wrote the code in the main method to call that function for the earthquakes file. 1 import cse163_utils 2 3 4 #Write your funciton here 5 6 def main(): 7 data = cse163_utils.parse('/course/lessons/earthquakes.csv') 8 print(average_magnitude (data, 2016)) 9 10 11 if __name__ __main__': 12 main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

=+ ^ What is the budget for this project?

Answered: 1 week ago

Question

3. What strategies might you use?

Answered: 1 week ago

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago