Question: Problem 1 : parse _ data ( filename ) : For this problem, write a function called parse _ data ( filename ) in the
Problem : parsedatafilename:
For this problem, write a function called parsedatafilename in the fishing.py file that reads the data in filename, uses csvDictReader to parse the file, and returns a dictionary containing the data for each country in the file.
Given the example CSV shown earlier, the dictionary returned from parsedata should look like the following:
"minyear": "maxyear": "farmed": "AMP": : : "wild caught": "AMP": : : "consumption": "AMP": : None, : "population": "AMP": : :
This is a triply nested dictionary; that is a dictionary with values as dictionaries where those values are also dictionaries. From outside in the structure of the dictionary is as follows:
For the outermost dictionary:
The keys are the four different types of measurements: farmed, wild caught, consumption, and population.
The values are dictionaries representing the data for that specific measure.
For the secondlevel dictionary, for example the value of the 'farmed' key from the outmost dictionary:
The keys are the threeletter country codes represented in the data. For example, AMPUSAMEX etc. These match the "country code" column from the CSV files.
The values are dictionaries, representing the data specific to the key ie country for the measure its nested within.
For the innermost dictionary:
The keys are the years represented in the data. Eg These should be integers.
The values are the measurements for that year or None if there is no data for that year represented as empty string from csvDictReader The types for these values should be as follows:
farmed, wild caught, and consumption should all be floatspopulation should be an integer
Consider as an example a subset of the above example dictionary: "farmed": "AMP": : : Reading this from the inside out we would say that in the country AMP had farmed metric tonnes of fish.
You should use the minyear and maxyear functions provided to you in utils.py imported for you in the starter file to get the range of years for which data is available. If youve created a csvDictReader as reader csvDictReaderfile then you can set the min and max years like dataminyear" minyearreaderfieldnames
Tip
We recommend that you open up the CSV files and examine the data before writing code. It is normal and expected to receive data that is incomplete. Using csvDictReader, those missing values will be given to you as empty strings; you should account for these in your code.
Tip
Although its not required, you may find it helpful to write some tests for this function to ensure it parses the file correctly and creates the expected dictionary structure correctly. Using the sample data for AMP aka AnkhMorpork, is a great test to write.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
