Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 2 7 Let's make a smaller dataframe to use while we are working out the larger problem. Create a dataframe called 'schools _ subset'

Task 27
Let's make a smaller dataframe to use while we are working out the larger problem.
Create a dataframe called 'schools_subset' from 'schools' that includes only Grade 3 for the year 2012. We are not going to need all the columns, so only add district, grade, year, and mean scale score to the new dataframe.
Display the schools_subset dataframe.
Task 28
Look up the DataFrame rank method. We will use this method to set the ranks. Since we want the highest rank to be 1, we need to set the 'ascending' parameter to the rank call to False.
Make a function called add_default_rank that takes a dataframe the first parameter and a 'column' parameter with the default 'Mean Scale Score' as the second paramter.
This function should create a new column called 'Default Rank' in the passed dataframe. The value of the new column should be the rank for the passed 'column' parameter.
Demonstrate your add_default_rank function works by calling the function on the 'students_subset' dataframe. Print the 'schools_subset' dataframe before and after the invocation of the function to confirm that (1) the 'Default Rank' column was added and (2) that the rank assigned to each row is correct based upon the 'Mean Scaled Score' value.
Task 29
Now that you have the add_default_rank function that works on a dataframe, you can use the apply method to apply that method to each group from a groupby.
Group the full 'schools' dataframe by grade and year, then apply add_default_rank to the groups. Store the results of this into a new 'schools2' dataframe.
Display the resulting 'schools2' dataframe.
Task 30
The 'schools2' now has a rank for each district for each grade and each year.
To fulfill the Mayor's ranking request, we can now produce the ordered list of districts with the top performers at the top of the list.
To do this, sum the 'Default Rank' column grouping by District and sorting the result using the sort_values method with "ascending" set to True and show the results.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

Students also viewed these Databases questions

Question

or the following function, find the val y={(8 if x 0):}

Answered: 1 week ago