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")

# Preview the data
schools.head()

# Start coding here...
# Add as many cells as you like...
# ---------------------------------------------------------
# 1. Schools with the best math results
#    (Math scores are considered "best" if at least 80% of 800, which is 640)
# ---------------------------------------------------------
best_math_schools = (
    schools.loc[schools["average_math"] >= 640, ["school_name", "average_math"]]
    .sort_values("average_math", ascending=False)
)

# ---------------------------------------------------------
# 2. Top 10 performing schools based on the combined SAT score
#    Total SAT is the sum of math, reading, and writing scores.
# ---------------------------------------------------------
# First, create a new column with the total SAT score:
schools["total_SAT"] = (
    schools["average_math"] + schools["average_reading"] + schools["average_writing"]
)

top_10_schools = (
    schools.loc[:, ["school_name", "total_SAT"]]
    .sort_values("total_SAT", ascending=False)
    .head(10)
)

# ---------------------------------------------------------
# 3. Identify the borough with the largest standard deviation
#    in the combined SAT score.
#    For each borough, compute:
#      - num_schools: number of schools in the borough
#      - average_SAT: mean of total_SAT for that borough
#      - std_SAT: the standard deviation of total_SAT
#
#    Round the numeric values to two decimals.
# ---------------------------------------------------------
# Group by borough and compute statistics.
borough_stats = (
    schools.groupby("borough")["total_SAT"]
    .agg(num_schools="count", average_SAT="mean", std_SAT="std")
    .reset_index()
)

# Round the numeric columns to two decimal places.
borough_stats["average_SAT"] = borough_stats["average_SAT"].round(2)
borough_stats["std_SAT"] = borough_stats["std_SAT"].round(2)
borough_stats["num_schools"] = borough_stats["num_schools"].astype(float).round(2)

# Identify the borough with the largest standard deviation in total SAT.
max_std_idx = borough_stats["std_SAT"].idxmax()
largest_std_dev = borough_stats.loc[[max_std_idx], ["borough", "num_schools", "average_SAT", "std_SAT"]]

# ---------------------------------------------------------
# Display the resulting DataFrames:
# ---------------------------------------------------------
print("Best Math Schools (average_math >= 640):")
print(best_math_schools.to_string(index=False))

print("\nTop 10 Schools by Combined SAT Score:")
print(top_10_schools.to_string(index=False))

print("\nBorough with the Largest Standard Deviation in Total SAT Score:")
print(largest_std_dev.to_string(index=False))