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...
#Which NYC schools have the best math results?

#subsetting just the school names and maths results
all_math_results = schools[['school_name', 'average_math']]
math.head()
#subsetting for the schools with the best maths result

best_math_schools = all_math_results[all_math_results['average_math'] > 640]
best_math_schools = best_math_schools.sort_values(by = 'average_math', ascending=False)
print(best_math_schools)
#What are the top 10 performing schools based on the combined SAT scores? 

#subsetting data for school names and their avg maths, reading and writing scores

filtered_df = schools[['school_name','average_math','average_reading','average_writing']]

#extracting the avg maths, reading and writing values as a list
average_math = schools['average_math']
average_reading = schools['average_reading']
average_writing = schools['average_writing']

#summing values as a list and adding as a brand new column to my filtered DataFrame

total_SAT = average_math + average_reading + average_writing
filtered_df['total_SAT'] = total_SAT

#sorting values from best to worst and taking only the 10 best schools
sorted_filtered_df = filtered_df.sort_values(by = 'total_SAT', ascending=False)
top_10_schools = sorted_filtered_df[0:10]

#only filtering the "top_10_schools" for just the school name and the total_SAT score

top_10_schools = top_10_schools[['school_name', 'total_SAT']]
print(top_10_schools)
#Which single borough has the largest standard deviation in the combined SAT score?

#firstly, we must append the original schools table with the combined SAT scores
total_SAT = average_math + average_reading + average_writing
schools['total_SAT'] = total_SAT
schools.head()
#let's group values by borough and apply std aggregation function on the total_SAT column

std = schools.groupby('borough')['total_SAT'].std().sort_values(ascending = False)
print(std)
num_schools = len( schools[ schools["borough"] == "Manhattan"] )
print(num_schools)

borough_total_SAT_mean = schools.groupby('borough')['total_SAT'].mean()
average_SAT = borough_total_SAT_mean['Manhattan']
average_SAT= round(average_SAT, 2)
print(average_SAT)

borough_total_SAT_std = schools.groupby('borough')['total_SAT'].std()
std_SAT = borough_total_SAT_std['Manhattan']
std_SAT = round(std_SAT, 2)
print(std_SAT)

data = [
    ['Manhattan', num_schools, average_SAT, std_SAT]
]

largest_std_dev = pd.DataFrame(data, columns=['borough', 'num_schools', 'average_SAT', 'std_SAT'])

print(largest_std_dev)