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...

# Convert SAT score columns to numeric
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')

# Remove rows with any missing SAT data
schools = schools.dropna(subset=['average_math', 'average_reading', 'average_writing'])

# -----------------------------
# 1. Best Math Schools
# -----------------------------
# Filter schools where average_math is at least 640 (80% of 800)
best_math_schools = schools[schools['average_math'] >= 640][['school_name', 'average_math']].copy()

# Sort descending by average_math
best_math_schools = best_math_schools.sort_values(by='average_math', ascending=False).reset_index(drop=True)

# -----------------------------
# 2. Top 10 Schools by Total SAT
# -----------------------------
# Calculate total SAT score
schools['total_SAT'] = schools['average_math'] + schools['average_reading'] + schools['average_writing']

# Create and sort top_10_schools DataFrame
top_10_schools = schools[['school_name', 'total_SAT']].copy()
top_10_schools = top_10_schools.sort_values(by='total_SAT', ascending=False).head(10).reset_index(drop=True)

# -----------------------------
# 3. Borough with Largest SAT Standard Deviation
# -----------------------------
# Group by borough and calculate stats
borough_stats = schools.groupby('borough').agg(
    num_schools=('school_name', 'count'),
    average_SAT=('total_SAT', 'mean'),
    std_SAT=('total_SAT', 'std')
).reset_index()

# Round values to 2 decimal places
borough_stats['average_SAT'] = borough_stats['average_SAT'].round(2)
borough_stats['std_SAT'] = borough_stats['std_SAT'].round(2)

# Find the borough with the largest std deviation
max_std_row = borough_stats.loc[borough_stats['std_SAT'].idxmax()]

# Save result in required format
largest_std_dev = pd.DataFrame([{
    'borough': max_std_row['borough'],
    'num_schools': max_std_row['num_schools'],
    'average_SAT': max_std_row['average_SAT'],
    'std_SAT': max_std_row['std_SAT']
}])

# -----------------------------
# Output (for verification)
# -----------------------------
print("Best Math Schools:")
print(best_math_schools)

print("\nTop 10 Schools by Total SAT:")
print(top_10_schools)

print("\nBorough with Largest Standard Deviation in SAT:")
print(largest_std_dev)





# Add as many cells as you like...