Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSV file : This is our name for a file containing ascii text where each line in the file represents one record of information; each

CSV file: This is our name for a file containing ascii text where each line in the file represents one record of information; each piece of info is surrounded by double quotes, and each of these quoted things is separated by a single comma. That's the exact formatting; nothing extra, nothing less. The very first line is the "header" row, which names the columns but is not part of the data. Here is a very small sample file that can be used in our project.

Note: a file's extension has no actual effect on its contents. These are ascii files, so you can/should edit them with your code editor just as easily as a .txt or .py file. We recommend not using Excel to open the files! It saves in a slightly different format, causing trouble.

"YEAR","GENDER","NAME","COUNT" "2009","MALE","DANIEL","3423" "2009","MALE","ANTHONY","3106" "2009","MALE","ANGEL","3058" "2010","MALE","JACOB","3368" "2010","MALE","DANIEL","3175" "2010","MALE","ANTHONY","2882"

Database: A database allows us to store multiple names from multiple years in an organized fashion. Our database is a dictionary whose keys are tuples of (name, gender), and whose values are lists of popularity length-3 tuples in the form of (year, count, rank). When there are multiple years data for a given (name, gender), the list should have multiple tuples sorted by years. An example dictionary corresponding to the CSV file above would be:

sample_db = { ('DANIEL', 'MALE'): [(2009, 3423, 1), (2010, 3175, 2)], ('ANTHONY', 'MALE'): [(2009, 3106, 2), (2010, 2882, 3)], ('ANGEL', 'MALE'): [(2009, 3058, 3)], ('JACOB', 'MALE'): [(2010, 3368, 1)]

}

This indicates that in 2009, Daniel was used as a male name 3423 times, and was the most popular male name that year in our records; also, Daniel was used as a male name 3175 times in 2010, and was the second-most popular male name that year in our records (second to Jacob). Similarly so for the rest of the entries.

Two kinds of Database: Ranked and Unranked

We either call a database ranked, where all ranks have been correctly filled in, or unranked, where ranks are either None or no longer correct due to an addition. It is common to begin filling in a database with None as the rank value, creating an unranked database, and then we will go back and recalculate/fix all the rankings. When naming function arguments, we use db and rdb accordingly to remind us what we've got.

We will use a few different csv files as our examples and in testing. They come from the shared files linked at the start of this document.

2

read_file(filename): This will accept the file name as a string, and assumes it is a CSV file as described above (with our name data in the same format as the example, but with any number of rows after the header row). It will open the file, read all the name entries, and correctly create the unranked database.

PYTHON 3

Function dealing with File Reading

This is the only function that deals with file reading; you can attempt it separately from all the other functions, because the other functions accept database dictionaries, and not file names they don't rely upon this function's output at all. If this function is taking up significant time please use your time wisely and keep working through the other required functions to maximize your time spent and score earned.

Return the resulting unranked database.

Set all rankings to None.

You can assume that for any given name/gender, there will be at most one entry for each year.

Sort all [(year,count,rank)] lists by year.

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

Students also viewed these Databases questions

Question

What is the purpose of trainControl function in R?

Answered: 1 week ago

Question

what is a peer Group? Importance?

Answered: 1 week ago

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago

Question

Question What happens to my plan if I die?

Answered: 1 week ago