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.

import pandas as pd

# Read the data from the 'schools.csv' file.
try:
    schools = pd.read_csv("schools.csv")
except FileNotFoundError:
    print("schools.csv not found. Using a sample DataFrame.")
    data = {
        "school_name": [
            "New Explorations into Science, Technology and Math High School",
            "Stuyvesant High School", "Bronx High School of Science",
            "Staten Island Technical High School", "Eleanor Roosevelt High School",
            "Queens High School for the Sciences at York College",
            "High School of American Studies at Lehman College",
            "Townsend Harris High School", "Bard High School Early College",
            "Brooklyn Technical High School", "Brooklyn Latin School",
            "High School for Mathematics, Science and Engineering at City College",
            "Essex Street Academy", "Lower Manhattan Arts Academy",
            "High School for Dual Language and Asian Studies",
            "Henry Street School for International Studies"
        ],
        "borough": [
            "Manhattan", "Manhattan", "Bronx", "Staten Island",
            "Manhattan", "Queens", "Bronx", "Queens", "Manhattan",
            "Brooklyn", "Brooklyn", "Manhattan", "Manhattan",
            "Manhattan", "Manhattan", "Manhattan"
        ],
        "average_math": [657, 754, 714, 711, 679, 673, 663, 621, 634, 582, 597, 613, 395, 418, 613, 410],
        "average_reading": [601, 706, 642, 660, 627, 634, 646, 619, 595, 563, 587, 566, 411, 428, 453, 406],
        "average_writing": [601, 680, 624, 636, 630, 597, 615, 617, 627, 563, 577, 566, 387, 415, 463, 381]
    }
    schools = pd.DataFrame(data)
# Convert score columns to numeric, handling potential non-numeric values
schools['average_math'] = pd.to_numeric(schools['average_math'], errors='coerce')
schools['average_reading'] = pd.to_numeric(schools['average_reading'], errors='coerce')
schools['average_writing'] = pd.to_numeric(schools['average_writing'], errors='coerce')
# Best Math Results ---
math_threshold = 0.80 * 800
best_math_schools = schools[schools['average_math'] >= math_threshold]
best_math_schools = best_math_schools[['school_name', 'average_math']].sort_values(
    by='average_math', ascending=False
)
print(best_math_schools)
print("\n" + "="*50 + "\n")
# --- Part 2: Top 10 Combined SAT Scores ---
schools['total_SAT'] = (
    schools['average_math'] + schools['average_reading'] + schools['average_writing']
)
top_10_schools = schools.sort_values(
    by='total_SAT', ascending=False
).head(10)[['school_name', 'total_SAT']]
print("DataFrame top_10_schools:")
print(top_10_schools)
print("\n" + "="*50 + "\n")
#  Largest Standard Deviation in Combined SAT Score ---
# Group by borough and calculate stats
borough_stats = schools.groupby('borough')['total_SAT'].agg(
    num_schools='count',
    average_SAT='mean',
    std_SAT='std'
)
# Find the row with the largest standard deviation and convert it to a DataFrame
largest_std_dev = borough_stats.loc[[borough_stats['std_SAT'].idxmax()]]

# Reset the index to make 'borough' a column, then round values
largest_std_dev = largest_std_dev.reset_index()
largest_std_dev = largest_std_dev.round(2)
print("DataFrame largest_std_dev:")
print(largest_std_dev)