Answered step by step
Verified Expert Solution
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
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() Data:
Problem:
Code:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started