Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how to sort and display the top five performing schools by %overall passing, using pandas my code as below: import pandas as pd import numpy

how to sort and display the top five performing schools by %overall passing, using pandas

my code as below:

import pandas as pd

import numpy as np

school_data_to_load = "../Resources/schools_complete.csv"

student_data_to_load = "../Resources/students_complete.csv"

school_data = pd.read_csv(school_data_to_load)

student_data = pd.read_csv(student_data_to_load)

school_data_complete = pd.merge(student_data, school_data, how="left", on=["school_name", "school_name"])

total_school = school_data["school_name"].count()

#calculate the total number of students

total_student = student_data["student_name"].count()

total_budget = school_data["budget"].sum()

average_maths_score = student_data["maths_score"].mean()

average_reading_score = student_data["reading_score"].mean()

passing_maths_percent = len(student_data[student_data['maths_score'] >= 50])/total_student*100

passing_reading_percent = len(student_data[student_data['reading_score'] >= 50])/total_student*100

overall_passing = len(student_data[(student_data['maths_score'] >= 50) & (student_data['reading_score'] >= 50)])/total_student*100

results_df = pd.DataFrame({

'Total Schools': [total_school],

'Total Students': [total_student],

'Total Budget': [total_budget],

'Average Math Score': [average_maths_score],

'Average Reading Score': [average_reading_score],

'% Passing Math': [passing_maths_percent],

'% Passing Reading': [passing_reading_percent],

'% Overall Passing': [overall_passing]

})

results_df

school_type = school_data[["type","school_name"]].set_index(["school_name"])["type"]

student_count = school_data_complete.groupby("school_name").count()["type"]

total_school_budget = school_data[["budget","school_name"]].set_index(["school_name"])["budget"]

per_student_budget = total_school_budget/student_count

math_score = school_data_complete.groupby("school_name").mean()["maths_score"]

math_score

reading_score = school_data_complete.groupby("school_name").mean()["reading_score"]

reading_score

math_passing = school_data_complete[school_data_complete['maths_score'] >= 50].groupby("school_name")['maths_score'].count() / student_count*100

reading_passing = school_data_complete[school_data_complete['reading_score'] >= 50].groupby("school_name")['reading_score'].count() / student_count*100

overall_passing = school_data_complete[(school_data_complete['reading_score'] >= 50)&(school_data_complete['maths_score'] >= 50)].groupby("school_name")['reading_score'].count() / student_count*100

school_df = pd.DataFrame({

'School Type': school_type,

'Total Students': student_count,

'Total School Budget': total_school_budget,

'Per Student Budget': per_student_budget,

'Average Math Score': math_score,

'Average Reading Score': reading_score,

'% Passing Math': math_passing,

'% Passing Reading': reading_passing,

'% Overall Passing': overall_passing

})

school_df

top_five_performing_schools = school_df.sort_values("% Overall Passing, ascending = False")

top_five_performing_schools.head()

csv link https://drive.google.com/drive/folders/1N5tUXjtgSq5G2msJy4tqzZOrNT4VaWcW?usp=sharing

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions