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...
# add new column with avg math scores as percentage
schools['avg_math_%'] = (schools['average_math'] / 800) * 100
schools.head()
# create a subset with only schools that have scored over 80% in avg math scores
top_math = schools[schools['avg_math_%'] >= 80]
top_math.head()
# select the two relevant columns for the question
best_math_schools = top_math[['school_name', 'average_math']]

# sort descending based on avg math scores
best_math_schools = best_math_schools.sort_values('average_math', ascending = False)

best_math_schools
# create a column with sum of all avg scores from 3 tests
schools['total_SAT'] = schools[['average_math', 'average_reading', 'average_writing']].sum(axis=1)
# add new column with total SAT as a %
schools['total_SAT_%'] = (schools['total_SAT'] / 2400) * 100
schools.head()
# create a subset with relevant columns for the question
top_10_schools = schools[['school_name', 'total_SAT']]

# sort values descending based on total SAT score
top_10_schools = top_10_schools.sort_values('total_SAT', ascending=False)

# slice the data to only include top 10 schools per question
top_10_schools = top_10_schools.head(10)

top_10_schools
schools
# group by borough and calculate the required stats based on question
borough_stats = schools.groupby('borough').agg(
    num_schools=('school_name', 'count'),
    average_SAT=('total_SAT', 'mean'),
    std_SAT=('total_SAT', 'std')
)
borough_stats
# find the single borough with largest std dev
largest_std_dev_borough = borough_stats['std_SAT'].idxmax()

# create subset for the borough with largest std dev
largest_std_dev = borough_stats.loc[[largest_std_dev_borough]].round(2)

# set borough as index
largest_std_dev.index.name = 'borough'

largest_std_dev