The arrays would not be the same because the indexes would be different If the

The arrays would not be the same because the indexes

This preview shows page 9 - 11 out of 11 pages.

The arrays would not be the same, because the indexes would be different. If the original namecolumn were to be sorted in a different order, the way in which "group" places the name values inarray would follow the new order, which would no longer match the previous order. Thought thenumber of elements are the same, the elements are no longer located at corresponding indexes,thus the arrays are not the same. (This is answered with the assumption that ordered by last nameand first name would generate a different order).Question 3.Setbiggest_range_deptto the name of the department with the largest salaryrange, where range is defined as thedifference between the highest salary and the lowest salaryin the department.Hint:First you’ll need to define a new functionsalary_rangewhich takes in an ar-ray of salaries and returns the salary range of the corresponding department.Then, setdepartment_rangesto a table containing the names and salary ranges of each department.In [44]:defsalary_range(array):high=max(array)low=min(array)returnabs(high-low)In [47]:department_ranges=profs.drop("name","position").group("department", salary_range).rdepartment_rangesOut[47]:department| rangeAfrican American Studies| 146781Agricultural and Resource Economics and Policy | 223480Anthroplogy| 265005Architecture| 240149Art History| 180065Art Practice| 152967Astronomy| 292362Bioengineering| 199195Biology| 292583Buddhist Studies| 0... (61 rows omitted)In [59]:department_ranges=profs.drop("name","position").group("department", salary_range).rdepartment_rangesbiggest_range_dept=department_ranges.sort("range",descending=True).column("departmenbiggest_range_deptOut[59]:'Economics'In [60]:_=ok.grade('q2_3')~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Running tests---------------------------------------------------------------------9
Background image
Test summaryPassed: 2Failed: 0[ooooooooook] 100.0% passed1.33. SubmissionOnce you’re finished, select "Save and Checkpoint" in the File menu and then execute thesubmitcell below. The result will contain a link that you can use to check that your assignment has beensubmitted successfully. If you submit more than once before the deadline, we will only grade yourfinal submission. If you mistakenly submit the wrong one, you can head tookpy.organd flag thecorrect version. To do so, go to the website, click on this assignment, and find the version youwould like to have graded. There should be an option to flag that submission for grading!In [61]:_=ok.submit()<IPython.core.display.Javascript object><IPython.core.display.Javascript object>Saving notebook... Saved'hw04.ipynb'.Submit... 100% completeSubmission successful for user: [email protected]URL: In [62]:# For your convenience, you can run this cell to run all the tests at once!importosprint("Running all tests...")_=[ok.grade(q[:-3])forqinos.listdir("tests")ifq.startswith('q')andlen(q)<=print("Finished running all tests.")Running all tests...
Background image
Image of page 11

You've reached the end of your free preview.

Want to read all 11 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes