Answered step by step
Verified Expert Solution
Link Copied!

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 21
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 time/years.)
Over time, is the district peformance improving, deteriorating, or staying the same for each grade?
Task 22
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 23
Use the apply method and your defined bottom function to display the full row for the bottom score in each grade.
Task 24
What insight did you get from the previous cell?
Task 25
Extend your selection above to show the row for the bottom score for the combination of grade and year.
Task 26
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 1, the second highest should get a rank of 2, 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 (i.e., 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 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

Students also viewed these Databases questions

Question

Why are antiviral drugs difficult to develop and use effectively?

Answered: 1 week ago