Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 2 1 Is there a trend on scores in the best district? Using the DataFrame plot method, plot the performance by grade of the
Task
Is there a trend on scores in the best district?
Using the DataFrame plot method, plot the performance by grade of the top distict across time.
Hint: Use selection, then groupby, then plot. Do not use a scatter plot for this task. You want a basic plot that shows the trend over timeyears
Over time, is the district peformance improving, deteriorating, or staying the same for each grade?
Task
Define a function bottom that returns the n rows with the lowest value for the specified column.
bottom should accept a dataframe as its first input, a parameter named n that accepts a number and provides a reasonable default, and a paramater called column that defaults to 'Mean Scale Score'.
Hint: This is similar to top
Demonstrate the function against the entire 'schools' dataframe.
Task
Use the apply method and your defined bottom function to display the full row for the bottom score in each grade.
Task
What insight did you get from the previous cell?
Task
Extend your selection above to show the row for the bottom score for the combination of grade and year.
Task
What insight did you get from the previous cell?
Results
The Mayor wants to recognize the top performing districts and direct additional resources to assist lower performing districts.
She asks you to rank the scores by performance as follows.
For each grade and year, rank each district based upon their 'Mean Scale Score. The district with the highest 'Mean Scale Score' should get a rank of the second highest should get a rank of etc.
After ranking for each grade and year, sum the ranks for each grade over all years. For the Mayor's purpose, the districts with the lowest total sum of the ranks ie the lowest rank numbers overall are considered the best performing schools.
This task is going to take a bit of work, so let's break the problem into incremental chunks of work.
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