Menu

[Solved]Introduction Lot Really Neat Things Data Files Find Internet Found Real Interesting Data F Q37192007

Introduction

We can do a lot of really neat things with data files that wefind on the Internet. I found a real, interesting data file aboutthe registered dogs in New York City (NYC)!

To get started you should download the following file byright-clicking on it and clicking “save as” or “save link as”:

  • dogs_of_NYC.txt

This file is fairly large but it contains some a list of datafor dogs registered in New York City. (It may take awhile for yourcomputer to load it in a text editor because it is so large!)Notice that the file has data seperated by tabs (not commas orspaces). This is new to us, but many data files are stored thisway. Note that when you use the .split() method later in your code,you will want to split on tabs like this:

lineList = line.split(“t”)

  

Specifics

In this assignment you will make several functions. You can makemore functions than the ones listed below to “help” in yourimplementation, but keep in mind that the program submission systemis expecting to see and call the 3 functions below.

In a file called: PA10.py

1) Create a funciton called: topTenNames()

>>>topTenNames () n/a 4025 Max 999 Bella 769 Lucky 710 Rocky 685 Coco 661 Buddy 599 Charlie 577 Princess 575 Lola 551

Ok, that was fun, but what about the top male and femalenames?

  • This function should open the dogs_of_NYC.txt file, read itline by line, and use a dictionary to store each dog name and thefrequency it occurs. It should then sort the results by thefrequency and print out the top ten. For example:

2) Create a function called:topTenNamesGender()

>>> topTenNamesGender (F) n/a 1742 Bella 766 Princess 574 Lola 549 Lucy 514 Daisy 506 Coco 440 Molly 413 Chloe 329 Maggie 3

Now you are contacted by the dog shelters in NYC. They areadvocating the policy of spaying/neutering dogs, and they want toknow which dog breeds tend to have the highest percentage ofspayed/neutered dogs.

  • This function takes in a “M” or “F” argument that specifies ifyou want male or female names. Your function should then onlycreate a dictionary for the selected gender, sort the results bythe frequence, and print out the top ten. For example:

3) Create a function called: spayedDogs()

This function should:

>>spayedDogs () 100.0 Russian Wolfhound 100.0 Belgian Griffon 100.0 Australian Kelpie 97.08029197080292 Greyhound 94.80519480

  • Print out the top ten percentages and breeds of dogs that arespayed/neutered. You really have to keep two data structures tosolve this question:
    • A dictionary of breed to total dogs of that breed
    • A dictionary of breed to total spayed/neutereddogs of that breed

Note: This turns out to be a great wrap up of lists,dictionaries, and functions. It uses a nice mixture of all of thetopics we have studied in the class. When you are done you willlikely be surprised at how small the code is. But it is very likelythat this will take you longer than you would like. To saveyourself some time we strongly suggest you sit down and workthrough the code on paper/pencil first. Think about all of theinformation that needs to be gathered, how it is gathered, how itis stored, and how it is processed.

Final Submission

Please upload your program to the program submission system. Theprogram is worth 25 points. The program submission system will berunning your three functions individually.

http://www.cs.uni.edu//~diesburg/courses/cs1510_sp19/homework/PA10/dogs_of_NYC.txt

>>>topTenNames () n/a 4025 Max 999 Bella 769 Lucky 710 Rocky 685 Coco 661 Buddy 599 Charlie 577 Princess 575 Lola 551 >>> topTenNamesGender (“F”) n/a 1742 Bella 766 Princess 574 Lola 549 Lucy 514 Daisy 506 Coco 440 Molly 413 Chloe 329 Maggie 316 >>> topTenNamesGender (“M”) n/a 2279 Max 99:1 Rocky 680 Lucky 599 Buddy 593 Charlie 531 Jack 349 Teddy 297 Toby 296 Buster 292 >>>topTenNamesGender (“A”) There were not 10 dogs with that gender >>spayedDogs () 100.0 Russian Wolfhound 100.0 Belgian Griffon 100.0 Australian Kelpie 97.08029197080292 Greyhound 94.8051948051948 Tibetan Terrier 94.29928741092637 German Shepherd Crossbreed 93.75 Briard 93.52692075015125 Labrador Retriever Crossbreed 93.33333333333333 “Coonhound, Treeing Walker” 92.85714285714286 Schipperkee Show transcribed image text >>>topTenNames () n/a 4025 Max 999 Bella 769 Lucky 710 Rocky 685 Coco 661 Buddy 599 Charlie 577 Princess 575 Lola 551
>>> topTenNamesGender (“F”) n/a 1742 Bella 766 Princess 574 Lola 549 Lucy 514 Daisy 506 Coco 440 Molly 413 Chloe 329 Maggie 316 >>> topTenNamesGender (“M”) n/a 2279 Max 99:1 Rocky 680 Lucky 599 Buddy 593 Charlie 531 Jack 349 Teddy 297 Toby 296 Buster 292 >>>topTenNamesGender (“A”) There were not 10 dogs with that gender
>>spayedDogs () 100.0 Russian Wolfhound 100.0 Belgian Griffon 100.0 Australian Kelpie 97.08029197080292 Greyhound 94.8051948051948 Tibetan Terrier 94.29928741092637 German Shepherd Crossbreed 93.75 Briard 93.52692075015125 Labrador Retriever Crossbreed 93.33333333333333 “Coonhound, Treeing Walker” 92.85714285714286 Schipperkee

Expert Answer


Answer to Introduction We can do a lot of really neat things with data files that we find on the Internet. I found a real, interes… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *