Answered step by step
Verified Expert Solution
Link Copied!

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 I/O exceptions
You will need to download this file:
census_population.csvDownload census_population.csv
This file contains the Annual Estimates of the Resident Population for Incorporated Places of 50,000 or More, Ranked by July 1,2021 Population: April 1,2020 to July 1,2021
Population class (5 points)
For this project, create a class called Population that has:
a container of your choice called file_import as an instance attribute.
an ordered dict called annual as an instance attribute
an ordered dict called biannual as an instance attribute
an import_csv method
a biannual_delta method
an annual_delta method
a search_by_city method
an export_csv method
import_csv method (5 points)
Create a method of the Population class called import_csv 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 file_import.
Use try-catch exception handling when file is not found
biannual_delta method (5 points)
Create a method of the Population class called biannual_delta that will perform the following tasks:
Check to see if the file_import is empty
If it is not empty, use a loop to read the file_import container (do not read the file here) and perform the following for each row:
Subtract the value for the Pop_Est_ Apr_2020 from the value for the Pop_Est_Jul_2020 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
annual_delta method (5 points)
Create a method of the Population class called annual_delta that will perform the following tasks:
Check to see if the file_import is empty
If it is not empty, use a loop to read the file_import container (do not read the file here) and perform the following for each row:
Subtract the value for the Pop_Est_Jul_2020 key from the value for the Pop_Est_Jul_2021 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
search_by_loc (5 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 0 values
export_csv method (5 points)
Create a method of the Population class called export_csv 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, Bi-Annual 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

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

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago