91.1k views
2 votes
For this lab, imagine you are an IT Specialist at a medium-sized company. The Human Resources Department at your company wants you to find out how many people are in each department. You need to write a Python script that reads a CSV file containing a list of the employees in the organization, counts how many people are in each department, and then generates a report using this information. The output of this script will be a plain text file.

User Yuko
by
5.1k points

1 Answer

3 votes

Answer:

import csv

import sys

file_csv = argv

with open( "file_csv", "rb" ) as file:

rowlist= csv.DictReader( file )

dict_count={ }

for row in rowlist:

dict_count[ row[ 'department' ] ] = dict_count.get( row[ 'department' ], 0 ) + 1

print( " The count of employees per department are", dict_count )

Step-by-step explanation:

The python script in the solution above is able to accept user input csv files via command prompt and get an output of the number of employees for each department.

User Afzal N
by
5.1k points