Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objectives: Create a class that has containers as instance attributes Read . csv files into container data types Write a . csv file from container
Objectives:
Create a class that has containers as instance attributes
Read csv files into container data types
Write a csv file from container data types
Handle file IO exceptions
You will need to download this file:
censuspopulation.csvDownload censuspopulation.csv
This file contains the Annual Estimates of the Resident Population for Incorporated Places of or More, Ranked by July Population: April to July
Population class points
For this project, create a class called Population that has:
a container of your choice called fileimport as an instance attribute.
an ordered dict called annual as an instance attribute
an ordered dict called biannual as an instance attribute
an importcsv method
a biannualdelta method
an annualdelta method
a searchbycity method
an exportcsv method
importcsv method points
Create a method of the Population class called importcsv that has a filename as a parameter. This method will perform the following tasks:
Read the file using the filename parameter and load the contents into fileimport.
Use trycatch exception handling when file is not found
biannualdelta method points
Create a method of the Population class called biannualdelta that will perform the following tasks:
Check to see if the fileimport is empty
If it is not empty, use a loop to read the fileimport container do not read the file here and perform the following for each row:
Subtract the value for the PopEst Apr from the value for the PopEstJul and store the results in the biannual ordered dict
Count each positive result in a local accumulator variable
When the loop completes, return the accumulator variable in a return statement
annualdelta method points
Create a method of the Population class called annualdelta that will perform the following tasks:
Check to see if the fileimport is empty
If it is not empty, use a loop to read the fileimport container do not read the file here and perform the following for each row:
Subtract the value for the PopEstJul key from the value for the PopEstJul key and store the results in the annual ordered dict
Count each positive result in a local accumulator variable
When the loop completes, return the accumulator variable in a return statement
searchbyloc points
Create a method that has a city, state string as a parameter. This method will:
Create a local container of your choosing called found. Define the container in this method; it should not be an instance attribute.
Search the annual ordered dict and the biannual ordered dict for the location provided by the parameter.
if found, store the values from both order dicts for that location in the found container and return it
if not found, return a container with values
exportcsv method points
Create a method of the Population class called exportcsv that has a filename as a parameter. This method will perform the following tasks:
Write the following to an output in csv format to the filename from the parameter:
Heading row: This will be the first row in the csv file and should contain the following values in each column of the csv file: Geographic Area, BiAnnual Delta, Annual Delta
Data rows: This will contain the values from the annual dictionary and biannual dictionary corresponding to the heading row keys
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started