Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Overview This lab exercise provides practice with lists, functions and namespaces in Python. ^ Instructions ^ Starter Code ^immigration.csv file Assignment Overview This lab

Assignment Overview This lab exercise provides practice with lists, functions and namespaces in Python.image text in transcribedimage text in transcribed

^ Instructions

image text in transcribed^ Starter Code

image text in transcribed^immigration.csv file

Assignment Overview This lab exercise provides practice with lists, functions and namespaces in Python You will work with a partner on this exercise during your lab session. Two people should work at one computer. Occasionally switch the person who is typing. Talk to each other about what you are doing and why so that both of you understand each step Immigration Immigration, especially illegal immigration, is a perennial, hot topic so in this lab we will take a look at some data. We use data from the Pew Research Center -data on illegal immigration is an estimate so its source is important.1 Pew has published trends covering decades such as the following figure, but we will examine one data point: 2016 (the latest year of good data) 12.SM 7.SM 2.SM 1990 1995 2000 2005 2010 2015 2020 We downloaded a spreadsheet from Pew Research for 2016 data on each state as well as a summary for the US. Each state is a row in the spreadsheet. We provide the spreadsheet as a CSV (comma separated value) file named immigration.csv Open the file in Excel (or a similar program) to see what we are providing. Pew uses the term "unauthorized" for what most people call "illegal." We are interested in answering three questions: 1. If we add up the individual state unauthorized immigration population (at index 1), do we get the same value as in the summative row labeled "U.S."? (Food for thought: why aren't they the 2. Which states have a larger percentage unauthorized immigrant population (at index 2) than the 3. Consider the column on the industry with the largest number of unauthorized immigrant workers same?) value in the summative row labeled "U.S."? (at index 9). Which industry is listed as the largest in the most states and how many states? We provide a skeleton program with a main) and four function headers, one function to read the file plus one function for each question 1. def read file (fp): this function takes a file pointer as an argument and returns a list of lists. The list of lists where each list is a list of the contents of each data row of the file ignoring header rows, footnote rows, and empty rows. The list will contain 52 lists, one for each http://www.pewhispanic.org/interactives/u-s-unauthorized-immigrants-by-state/ of the fifty states plus the District of Columbia and one summative row (the row labeled "U.S.") The order of the list will be the same as the order in the file. If you wish, you may use the fact that Wyoming is the last data line of the file to terminate your loop. (Hint: use csv.reader ), see notes below.) 2. def get totals (L): this function takes the list of lists returned by the read file () function and returns two values. The data of interest for this function is the column at index 1 unauthorized immigrant population. Return the value in the summative row (labeled "US.") and the sum of the other 51 data rows. The purpose of this function is to gather data to answer question #1 above. 3. def get largest states (L): this function takes the list of lists returned by the read file () function and returns a list. The data of interest for this function is the column at index 2: unauthorized immigration % of population. The returned list is a list of states whose value is greater than the summative value (the value in the row labeled "U.S."). Since "District of Columbia" is in the file we will include it as a "state." The returned list will be in alphabetical order (the order of the original file). The purpose of this function is to gather data to answer question #2 above. 4. def get industry counts (L): this function takes the list of lists returned by the read file() function and returns a list of lists. The data of interest for this function is the column at index 9: industry with largest number of unauthorized immigrant workers. The list of lists returned is a list of industries and occurrences in the column (excluding the summative data from the row labeled U.S."). The returned list will be sorted by occurrences (largest first) and will look like this [ [industryl,countl], [industry2, count2],.] The purpose of this function is to gather data to answer question #3 above. (Hint: use key-itemgetter (1) to sort on index 1 of the lists.) Notes and Suggestions Using the CSV package: Remember import csv eader csv.reader(f next (reader,None) attaches a reader to the skips a line, such as a heade line in ader: a lis import csv from operator import itemgetter INDUSTRIES = [ 'Agriculture', 'Business services. "Construction', 'Leisure/hospitality', 'Manufacturing' ] def read file(fp): '" 'Docstring''" pass def get_totals (L): "'Docstring' pass def get industry counts (L): '''Docstring pass def getlargest states (L): 'Docstring'' pass def main(): fp - open("immigration.csv") = readfile(fp) - us_pop, total_pop get_totals (L) print(" Data on Illegal Immigration " ) print("Summative:", us pop) print( "Total :", total_pop) states- get largest states (L) print(" States with large immigrant populations") for state in states: state state.replace('In','') print (state) "Estimated unauthorized immigrant population and selected characteristics, by state, 2016,,,.,,,,,,,, State,"Unauthorized immigrant population ",unauthorized immigrant % of population, Unauthorized % of immigrant population, % of K-12 students with unauthorized immigrant parent(s), % Mexican of unauthorized immigrants,% of unauthorized immigrant adults in the .s. for 5 years or less, "change in unauthorized immigrant population, 2007-2016",Unauthorized immigrant of labor force, Industry with largest number ofunauthorized immigrant workers, industry with largest of workers who are unauthorized immigrants, Occupation with largest number ofunauthorized immigrant workers ,occupation with largest % of workers who are unauthorized immigrants u. s . , " 10, 700, 000" , 3 . 34, 24, 7 .64, 51, 189 , "-1, 550, 000", 48%, construction, Agriculture, service, Farming Alabama, 55,000" , 1 . 2 % , 34% , 3 . 38, 598, 138, "-15,000 " , 1 . 78, Construction, Construction, Service, Farming Alaska, "5,000", 1.08, 138,0.5%,238,43% , Not sig., 1.7%,Manufacturing, Hanufacturing,Production,Production Arizona, "275,000" , 3.9%,288, 10.7%, 78%, 134,"-220,000",5.7% , Business services , Agriculture , service,Farming Arkansas , " 55 , 000" , 1 . 9% , 41, 6 34, 64% , 15% , "-10, 000" r 28% , Manufacturing, construction, service, construction California, "2,200,000",5.68, 20%, 13.38, 698, 10%,-550,000. 8.68,Leisure/hospitality,agriculture, service, Farming Colorado, "190,000",3.48,34%, 10.68, 708, 148,Not sig., 4.68,Construction , Construction, Service,Construction connecticut,' 120,000", 3.58,238, 6.98, 148,21%,Not sig., 4.98 , Business services , Construction ,service , construction Delaware, "30,000", 3.0%,31%, 7.0%, 38%,29%,Not sig. ,4.2%, construction , construction , service, Farming District of Columbia", "25,000",3.8%288, 9.08,5%,21% , Not sig., 4.78,Leisure/hospitality,Construction,Service,Construction Florida, "775, 000" , 388, 188, 7 , 18, 158, 298, "-240,000 . , 5 " 68,Construction, Agriculture, Service, Farming Georgia,"400,000", 3.8%, 368,8.68, 498, 178,Not sig. ,5.48,Construction,Construction,Service,Construction Hawaii, "45,000",3.34, 178, 7.08,68, 34% , Not sig. ,4.5% ,Leisure/hospitality , Agriculture, service , Farming Idaho, "35,000", 2.24,37%, 5.74,798, 19% , Not sig. ,3.1%,Agriculture,Agriculture, service,Farming riinois," 400,000",3.2%, 228, 7.89, 718, 11%, "-140,000", 4.8%,Manufacturing, Manufacturing, Service, Production Indiana, "100,000", 1.58,29%,4.28, 598,238,Not sig.,2.1%,Manufacturing , Agriculture , Service, Farming Iowa, "50,000., 1.78, 318, 4.28,56%,268, Not sig., 2.2%,Manufacturing , Manufacturing , Production , Farming Kansas, "75,000",2.6%,358,7.6% ,69%,16%,Kot sig., 3.7%,Hanufacturing,construction,service , construction Kentucky, "35,000",0.89, 22%,1.64,48%, 24% , Not sig., 1.1%,Construction , Agriculture, service , Farming Louisiana, " 70,000", 1-5% , 368 , 2-7%, 288, 23%, "15,000'. 2.08,Construction, Construction, Construction, Construction Maine , "

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

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

Define the goals of persuasive speaking

Answered: 1 week ago