QuestionQuestion

Working with raw data is not easy, data coming from the real world is generally messy. In this assignment you will work with files containing raw data and try to parse and manipulate the data. Download zoo dataset files from Blackboard and write code to convert the raw data into more human-readable CSV format.

aardvark, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 0, 1, 1
antelope, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1
bass, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4

Lot of times it is important to keep the data into compact machine-readable formats when the data is large, but this data is not large. Goal is to write a code to convert it to readable CSV file (Python preferably, if you are comfortable in some other programming language, talk to me). Note that there are no column headers in the data above, so not clear what these 1s and Os are telling you need to cross-reference them from another file. Specifically, one would like the output to look like:

AnmialName, Hair, Feathers, Eggs, Milk, Airborne, Aquatic, Pedator
aardvark, Yes, No, No, Yes, No, NO, Yes, Yes, Yes, Yes,
antelope, Yes, No, No, Yes, No, No, No, Yes, Yes, Yes, No,

To do this, you need to check both files "zoo.data" and "zoo.names". The information in "zoo.names" is relatively unstructured, you can find the Attribute Information in this file. You also need to look at types of each attribute (Boolean, Numeric, etc.). Next, you need to load the data from "zoo.data", convert Boolean value 1 to "Yes" and 0 to "No", make sure Numeric remain numeric. You need to write the values to CSV file.

    Solution PreviewSolution Preview

    These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

    # -*- coding: utf-8 -*-

    def main():

        dataFile = 'zoo.data' # Input file name in string type

        header = ['Name',
                 'hair',
                 'feathers',
                 'eggs',
                 'milk',
                 'airborne',
                 'aquatic',
                 'predator',
                 'toothed',
                 'backbone',
                 'breathes',
                 'venomous',
                 'fins',
                 'legs',
                 'tail',
                 'domestic',
                 'catsize',
                 'type'] # A list of strings variable for holding the header names for CSV Output file

        fileHandler = open(dataFile) # that takes a file name a returns a file handler

        animals = fileHandler.readlines() # Returns a list of lines inside txt file
        resultAnimals = list() # Output list of lines to be written in a file...

    By purchasing this solution you'll be able to access the following files:
    Solution.zip.

    $13.50
    for this solution

    PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

    Find A Tutor

    View available Python Programming Tutors

    Get College Homework Help.

    Are you sure you don't want to upload any files?

    Fast tutor response requires as much info as possible.

    Decision:
    Upload a file
    Continue without uploading

    SUBMIT YOUR HOMEWORK
    We couldn't find that subject.
    Please select the best match from the list below.

    We'll send you an email right away. If it's not in your inbox, check your spam folder.

    • 1
    • 2
    • 3
    Live Chats