Question: import pandas as pd import matplotlib.pyplot as plt import numpy as np import helper import sim _ parameters def calculate _ number _ of _
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import helper
import simparameters
def calculatenumberofsamplesdf countries, sampleratio:
function that returns a nested dictionary with the structure: 'Afghanistan' : less :
population # dictionary, storing each country with its population
for country in countries:
# filter the dataframe to get the population of the current country
countryrow dfdfcountry country
populationcountry countryrowpopulationvalues # now each country has it's population
numsamplescountry # list storing order of the countries in population the number of samples of each country
# calculate the number of samples for each country
for country in population:
numsamplescountry.appendintpopulationcountrysampleratio # floor value using and casting into integer
# harcoded for speeding up process, TODO eliminate this line
numsamplescountry
print
Number of samples of each country we are going to use for the moment faster execution:
numsamplescountry
# Calculate the number of samples of each age group inside each country
# nested dictionary key: country, value: dictionary with each age group the number of samples
numgroupsamplesinsidecountry # eg: 'Afghanistan' : less :
# TODO Calculate the values of the dictionary
#
return numgroupsamplesinsidecountry
Please complete the TODO section of this code.
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
