Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, how do you write the python code for Question 3? Thanks. 2. Faculty salaries This exercise is designed to give you practice using the
Hi, how do you write the python code for Question 3? Thanks.
2. Faculty salaries This exercise is designed to give you practice using the Table methods pivot and group. Here is a link to the Python reference page in case you need a quick refresher. Run the cell below to view a demo on how you can use pivot on a table. (Thank you to past staff Divyesh Chotai) In [5]: from IPython.display import YouTubevideo YouTubevideo ("4WZXO8EKLAg") Out[5]: DATA Pivot Tables Demo Calor ecolate atrawberry vanilla dwrthroun consplvot/"Flavor", "Color","Price": np. sum) ones In the next cell, we load a dataset created by the Daily Cal which contains Berkeley faculty, their departments, their positions, and their gross salaries in 2015. In [6]: raw_profs = Table.read_table("faculty.csv").where("year", are.equal_to(2015)).drop("year", "title") profs = raw_profs.relabeled("title_category", "position") profs Out[6]: ne department position gross_salary CYNTHIAABAN South & Southeast Asian Studies lecturer 84450 PIETER ABBEEL Computer Science associate professor 184998 SALLY ABEL Law lecturer 3468 ELIZABETH ABEL English professor 138775 DOR ABRAHAMSON Education associate professor 100300 KATHRYN ABRAMS Law professor 319893 BARBARA ABRAMS Public Health professor 191162 SARAH ACCOMAZZO Social Welfare lecturer 14779 CHARISMA ACEY City and Regional Planning assistant professor 101567 DAVID ACKERLY Biology professor 182288 ... (2049 rows omitted) We want to use this table to generate arrays with the names of each professor in each department Question 1. Set prof names to a table with two columns. The first column should be called department and have the name of every department once, and the second column should be called faculty with each row in that second column containing an array of the names of all faculty members in that department Question 3. Set department_ranges to a table containing departments as the rows, and the position as the columns. The values in the rows should correspond to a salary range, where range is defined as the difference between the highest salary and the lowest salary in the department for that position. Hint: First you'll need to define a new function salary_range which takes in an array of salaries and returns the range of salaries in that array. In [9]: # Define salary_range first def salary_range (salaries): return max(salaries) - min(salaries) department_ranges = profs.drop("name", "position").group("department", salary_range).relabeled ("gross_salary salary_range","sprei department_ranges = ... department_ranges Out[9]: EllipsisStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started