Answered step by step
Verified Expert Solution
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
Let's make a smaller dataframe to use while we are working out the larger problem.
Create a dataframe called 'schoolssubset' from 'schools' that includes only Grade for the year 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 schoolssubset dataframe.
Task
Look up the DataFrame rank method. We will use this method to set the ranks. Since we want the highest rank to be we need to set the 'ascending' parameter to the rank call to False.
Make a function called adddefaultrank 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 adddefaultrank function works by calling the function on the 'studentssubset' dataframe. Print the 'schoolssubset' dataframe before and after the invocation of the function to confirm that the 'Default Rank' column was added and that the rank assigned to each row is correct based upon the 'Mean Scaled Score' value.
Task
Now that you have the adddefaultrank 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 adddefaultrank to the groups. Store the results of this into a new 'schools dataframe.
Display the resulting 'schools dataframe.
Task
The 'schools 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 sortvalues method with "ascending" set to True and show the results.
Step 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