Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the following functions below in python. I am using a csv file which can be found here- https://1drv.ms/x/s!Aj0EGBNy0RCLjWRF51Lye2y56X8H This program will

I need help with the following functions below in python. I am using a csv file which can be found

here- https://1drv.ms/x/s!Aj0EGBNy0RCLjWRF51Lye2y56X8H

This program will require you to work with modules, global variables, CSV files, and nested dictionaries.

  • You will be writing a module. The module should not have a main or call any of its functions at the top level. It should only define functions and global variables.
  • As a convention, you might want to start all of the global variables in the module with an _ (underscore) so they stand out. These will be a useful place to hold the dictionaries you create during the analysis.
  • You need to implement below functions:
  1. init() - This function should parse your CSV file and read all the lines. Lines read by this function should be reused by rest of the functions. In this way you avoid reading file multiple times for each of your functions.

  2. genderDistribution() - Should return a dictionary for entire M and F population in the school

  3. collegeDistribution() - Should return a nested dictionary for each of the college in the school with it's respective M and F population

  4. departmentDistribution() - Should return a nested dictionary for each of the department in the school with it's respective M and F population

  5. majorDistribution() - Should return a nested dictionary for each of the major in the school with it's respective M and F population

  6. termDistribution() - Should return a nested dictionary for each term in the school with it's respective M and F population

  • For each of the below columns, create a dictionary with M and F population:

    • College
    • Department
    • Major
    • Term

    In most cases, dictionaries are nested so you might want to review how to create, access, and update nested dictionaries.

  • Comma Separate Value (CSV) files are fairly common and useful since they may easily to loaded into a spreadsheet for analysis.

Here is the main:

image text in transcribed

1 import diversityanalysis 4 def printTitle(title): print('n F M F/M +title) 8 def printDistribution(gender, item) f gender.get('F',e) m gender get('M',0) rf/m if m 0 else 0.0 10 12 13 14 15 def main): 16 17 18 19 20 21 printDistribution (gender, "Gender") print ("%6d %6s %3.1f %s" % (f, m, r, item)) diversityanalysis.init('genderdata.csv') genderdiversityanalysis.genderDistribution() printTitle('Total') college diversityanalysis.collegeDistribution() printTitle( 'College') for k in sorted (college.keys ()): 23 24 25 26 27 28 29 30 31 32 printDistribution (college[k],k) department-diversityanalysis.departmentDistribution() printTitle( 'Department') for k in sorted(department.keys()) printDistribution (department[k],k) major diversityanalysis.majorDistribution() printTitle ( 'Major') for k in sorted (major.keys()) 34 35 36 37 38 printDistribution (major[k],k) termdiversityanalysis.termDistribution() printTitle('Term for k in sorted(term.keys()): 40 41 42 43 44 main printDistribution(term[k],k) 1 import diversityanalysis 4 def printTitle(title): print('n F M F/M +title) 8 def printDistribution(gender, item) f gender.get('F',e) m gender get('M',0) rf/m if m 0 else 0.0 10 12 13 14 15 def main): 16 17 18 19 20 21 printDistribution (gender, "Gender") print ("%6d %6s %3.1f %s" % (f, m, r, item)) diversityanalysis.init('genderdata.csv') genderdiversityanalysis.genderDistribution() printTitle('Total') college diversityanalysis.collegeDistribution() printTitle( 'College') for k in sorted (college.keys ()): 23 24 25 26 27 28 29 30 31 32 printDistribution (college[k],k) department-diversityanalysis.departmentDistribution() printTitle( 'Department') for k in sorted(department.keys()) printDistribution (department[k],k) major diversityanalysis.majorDistribution() printTitle ( 'Major') for k in sorted (major.keys()) 34 35 36 37 38 printDistribution (major[k],k) termdiversityanalysis.termDistribution() printTitle('Term for k in sorted(term.keys()): 40 41 42 43 44 main printDistribution(term[k],k)

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_2

Step: 3

blur-text-image_3

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

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions

Question

Understand the advantages and disadvantages of teams.

Answered: 1 week ago