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

# My solution

# Which NYC schools have the best math results?
# "Best" means >= 80% of the max score (800) → 0.8 * 800 = 640. Keep only school_name and average_math columns. Sort in descending order of average_math and reset index to keep row numbers clean
best_math_schools = (
    schools.loc[schools["average_math"] >= 0.8 * 800, ["school_name", "average_math"]]
      .sort_values(by="average_math", ascending=False)
      .reset_index(drop=True)
)
print("Best Math Schools:\n", best_math_schools)


# Top 10 schools based on total SAT
# Create a total_SAT column by summing math, reading, and writing scores
schools["total_SAT"] = (
    schools["average_math"] + schools["average_reading"] + schools["average_writing"]
)
# Select only the school_name and total_SAT columns. Sort in descending order of total_SAT. Take the first 10 rows for the top 10
top_10_schools = (
    schools.loc[:, ["school_name", "total_SAT"]]
      .sort_values(by="total_SAT", ascending=False)
      .head(10)
      .reset_index(drop=True)
)
print("\nTop 10 Schools:\n", top_10_schools)


# Borough with largest standard deviation in total SAT
# Group the data by borough. Calculate:
#   - num_schools = number of schools in the borough
#   - average_SAT = mean of total_SAT
#   - std_SAT = standard deviation of total_SAT
borough_stats = (
    schools.groupby("borough")["total_SAT"]
      .agg(num_schools="count", average_SAT="mean", std_SAT="std")
      .reset_index()
)

# Find the borough with the maximum std_SAT
# Convert to DataFrame to match output requirement
largest_std_dev = borough_stats.loc[borough_stats["std_SAT"].idxmax()].to_frame().T

# Round average_SAT and std_SAT to 2 decimal places
largest_std_dev[["average_SAT", "std_SAT"]] = (
    largest_std_dev[["average_SAT", "std_SAT"]]
    .astype(float)
    .round(2)
)

print("\nLargest Std Dev Borough:\n", largest_std_dev)