Question: *ONLY NEED QUESTION 4* In this part you will write a python script that explores the dataset and collects some statistics about the different attributes.

*ONLY NEED QUESTION 4*

In this part you will write a python script that explores the dataset and collects some statistics about the different attributes.

  1. Write a python script that reads the adult.data file line by line, extracts the education attribute from each line and prints it into an output file named adult.ed.data

The output file should contain this data:

Bachelors

Bachelors

HS-grad

11th

Bachelors

Masters

.

.

  1. Modify the script to compute the number of distinct values that the education column can take. For example, if the dataset contains education values of
    • Bachelors
    • HS_grad
    • Masters
    • 11th
    • 9th
    • PhD

Then the number of distinct values for the education column is 6.

Use a dictionary to store the distinct values while reading the dataset file, then count the number of entries in the dictionary.

  1. Modify your script to compute the frequency of each education value in the dataset file. That is, how many people have a Bachelors degree, how many people are HS-grad, etc.?

Use a dictionary to store the distinct values and their counts as key-value pairs. Modify the dictionarys keys and values as you read the dataset line by line. Print the key-value pairs of the final dictionary.

  1. (Extra Credit: 10 points) Repeat this processing with all columns in the dataset file. That is, generate the same counts for distinct values for the age, work class, education , and income columns. Print the dictionaries for all columns.

Hint: You can do so by creating a function that takes as input a column number and generates the counts for this column. Then use a for loop to call this function for each column in the dataset. Since the dataset contains 15 columns, the for loop counter that represents the column number should iterate from 0 to 14.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!