Skip to content

Photo by Jannis Lucas on Unsplash.

Every year, American high school students take SATs, which are standardized tests intended to measure literacy, numeracy, and writing skills. There are three sections - reading, math, and writing, each with a maximum score of 800 points. These tests are extremely important for students and colleges, as they play a pivotal role in the admissions process.

Analyzing the performance of schools is important for a variety of stakeholders, including policy and education professionals, researchers, government, and even parents considering which school their children should attend.

You have been provided with a dataset called schools.csv, which is previewed below.

You have been tasked with answering three key questions about New York City (NYC) public school SAT performance.

# Re-run this cell 
import pandas as pd

# Read in the data
schools = pd.read_csv("schools.csv")


print(schools.head())


# First problem

#Getting the 0.8 of 800 maximum score

bestMath = 0.8 * 800

#copy the original dataframe to new
temp_schools = schools.copy()

#subset the temp schools showing only schools with 640 or greater scores in math
temp_schools = temp_schools[temp_schools["average_math"] > bestMath]

#storing to best_math_schools dataframe the school and their average math scores sorted by the scores in descending order
best_math_schools = temp_schools[["school_name", "average_math"]].sort_values("average_math", ascending=False)

print(best_math_schools)
print(temp_schools.columns)


#second problem
temp_schools = schools.copy()
#Adding TOTAL_SAT column in the temp_schools dataframe. Total SAT is all the average scores
temp_schools['total_SAT'] = temp_schools[["average_math", "average_reading", "average_writing"]].sum(axis=1)
temp_schools.sort_values(by="total_SAT", ascending=False, inplace=True)

#Getting top 10 schools

top_10_schools = temp_schools[["school_name", "total_SAT"]]
top_10_schools = top_10_schools[:10]
print(top_10_schools)

#Third problem
temp_schools = schools.copy()
#Adding TOTAL_SAT column in the temp_schools dataframe. Total SAT is all the average scores
temp_schools['total_SAT'] = temp_schools[["average_math", "average_reading", "average_writing"]].sum(axis=1)
borough_schools = round(temp_schools.groupby("borough")["total_SAT"].agg(["count", "mean", "std"]), 2).sort_values(by="std", ascending=False).reset_index()
borough_schools.rename(columns={"count": "num_schools", "mean": "average_SAT", "std": "std_SAT"}, inplace=True)

#Getting the single borough
largest_std_dev = borough_schools.iloc[[0],0:]
largest_std_dev = pd.DataFrame(largest_std_dev)
print(largest_std_dev)