Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Datafile Overview population. json contains population data by year (i.e. 1950 through 2015) for world regions. Each JSON object in the file has three keys:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed Datafile Overview population. json contains population data by year (i.e. 1950 through 2015) for world "regions". Each JSON object in the file has three keys: "population" (divided by 1000 ), "region", and "year". The values associated with the "region" key identify individual countries as well as aggregated groups of countries. These are some examples of JSON objects from the file: {"population":2536274.721,"region":"WoRLD","year":"1950"}{"population":554419.275,"region":"China","year":"1950"}{"population":376325.2,"region":"India","year":"1950"}{"population":1404061.59,"region":"ASIA","year":"1950"} Problem Description Using data from population.json, write code to create a report that includes a table to show the percentage of a specific country's population relative to the world's population for the years 1990 through 2015. Your code should produce reports for the countries of India and China, and should match the examples below as closely as possible. The tables shown here are truncated for illustration. Your output should show all years in the period 1990 through 2015. India's percentage of WORLD's population by year. Include a title for each report. The table columns are Year, Country, WORLD, and Percent, and the table will have a row for each year of data. Below the table, the following summary statistics should be included: - country's average percentage for all years (i.e. 1990 to 2015) - country's overall growth for all years - world's overall growth for all years Percent for a given year: ()100 Average percentage for all years: (())100 Requirements You are free to follow any approach you like, but your solution code must: - programmatically read data from the provided .json file - subset data as specified in the Problem Description section - calculate summary statistics as specified in the Problem Description section - employ at least one substantive custom function - not include hardcoding where a programmatic approach can be used Suggested Approach 1. Read population. json into a Python list of dictionaries. To confirm that the data from the file has been read correctly, print an element from the list. The first element should look like this: {population:2536274.721,region:WORLD,year:1950} 2. Next, build three new lists from the list of dictionaries: one list holds all the dictionaries for the WORLD, the second contains lists for China, and the third contains lists for India. Each of these lists should be subsetted to include only data for the years 1990 onward. Confirm that you've properly subsetted the data. The data for each region is sorted by year so there should be no need to sort the new lists. The first elements in the WORLD, China, and India lists should look like this: {population:5330943.46,region:WORLD,year:1990}{population:1172445.2,region:China,year:1990}{population:870133.48,region:India,year:1990} 3. Define a function called generate_report (). This function will accept at least two formal parameters - pontry and pworl d (i.e. the subsetted list of dictionaries described in Step 2) - and will output a report that includes a population comparison table as shown earlier in the Problem Description section. The function wil: - iterate over pentry (i.e. year by year) and calculate the percentage of the country's population relative to pworld's population - output a row for each year as shown in the example tables provided earlier - keep track of the yearly percent for use in calculating the average percentage for all years - use the country's first and last year's population values to calculate its overall growth for the time period - use the WORLD's first and last year's population values to calculate its overall growth for the time period - output a table and summary statistics as shown in the example tables 4. Finally, call the generate_report () function and provide the appropriate parameters to print the summary table for China. In another cell, call generate_report () again to print the summary table for India

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions