Use Python 3 for the following question. The link to the cvs data file is: https
ID: 3871807 • Letter: U
Question
Use Python 3 for the following question. The link to the cvs data file is: https://www.dropbox.com/s/c7mjpyibhufsg5x/employees.csv?dl=0
The City of Chicago publishes lots of open data for citizens like us to analyze. For this problem, you are provided a comma-separated value file employees.csv which contains information on all public employees in Chicago, their occupations, their departments, and their annual salary or hourly pay, whichever is applicable. Write a program that prints out the names and salaries of N highest paid (salaried) employees of Chicago. N should be given as a command line argument. Although we have not covered it yet, you are allowed to use the csv standard library module if you wish. Otherwise, using normal file/strings methods will suffice. The csv module helps us deal with the fact that the first column has values containing commas, but is not strictly necessary here.Explanation / Answer
import csv myfile = open(‘employees.csv’, “rb”) reader = csv.reader(myfile) rownum = 0 column = 0 for row in reader: if rownum ==0: header = row else: column= 0 for col in range(sys.argv[1]): print ‘%-8s: %s’ % (header[colnum], col) column + = 1 rownum + = 1 myfile.close()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.