December 2018
Beginner to intermediate
682 pages
18h 1m
English
Steps 2 and 3 find the maximum salary for each department. For automatic index alignment to work properly, we set each DataFrame index as the department. Step 5 works because each row index from the left DataFrame; employee aligns with one and only one index from the right DataFrame, max_dept_sal. If max_dept_sal had repeats of any departments in its index, then the operation would fail.
For instance, let's see what happens when we use a DataFrame on the right-hand side of the equality that has repeated index values. We use the sample DataFrame method to randomly choose ten rows without replacement:
>>> np.random.seed(1234)>>> random_salary = dept_sal.sample(n=10).set_index('DEPARTMENT')>>> random_salary
Notice how there ...