Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python 3.5: 3. Work with Census Data: Dowload the following le: http://www

ID: 3767143 • Letter: U

Question

Using Python 3.5:

3. Work with Census Data: Dowload the following le:
http://www.census.gov/population/www/censusdata/files/urpop0090.txt
The census le is a text le with data for the 10-year census from 1900 to 1990 (e.g.,
1900, 1910, 1920, . . . ). It has population data for each state as well as regional
and overall data. Each state is on its own line, but the data are grouped so that
only three decades of data are on each line|complicating the task of extracting
the data. In addition, the data are further broken down into total, urban, rural,
and percentages. Write a program that for any census year input (e.g., 1970)
the program will print the state and its total population with the minimum and
maximum. For example:
Enter census year 1900 to 1990: 1970
Minimum: (302853, 'Alaska')
Maximum: (19971069, 'California')
The output is displayed as a tuple as a hint to assist with solving the problem
rather than illustrating readable output. Some points to consider:
(a) Begin by generating clean data: there are footnotes that need to be elim-
inated, numbers contain commas, some rows (lines) have data you are not
interested in (e.g., region data), you are not interested in all columns (e.g.,
percentages), and so on. Simply printing the lines with extraneous data re-
moved is a good start.
(b) You will likely want to combine multiple state name strings into one, e.g.,
New" York" becomes New York."
(c) A tuple (population, state) provides a way to tag population data with a state
in a way that allows a list of tuples to be sorted (remember that by default,
sorting uses the rst value).

Explanation / Answer

import numpy as np

import csv as csv

readdata = csv.reader(open("where_you_saved_the_file"))

<_csv.reader object at 0x05397EF0>

for row in readdata:

print row

data = []

for row in readdata:

data.append(row)

Header = data[0]

data.pop(0)

pop1910 = []

pop1990 = []

for i in range(len(data)):

pop1910.append(int(data[i][1]))

pop1910.append(int(data[i][2]))

for i in range(len(data)):

diff = int(data[i][2]) - int(data[i][1])

data[i].append(diff)

print pd.DataFrame(data, columns = Header)

print "Total in 1910: %d" % (np.sum(pop1910))

print "Average in 1910: %d" % (np.mean(pop1910))

print "Standard Deviation in 1910: %d" % (np.std(pop1910))

print "Total in 1990: %d" % (np.sum(pop1990))

print "Average in 1990: %d" % (np.mean(pop1990))

print "Standard Deviation in 1990: %d" % (np.std(pop1990))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote