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...
#Calculating top schools with average math percentage greater than 80
best_math_schools = schools[schools['average_math']/800 >= 0.8][['school_name','average_math']].sort_values(by = 'average_math', ascending = False)
#Printing the resulting df
print(best_math_schools)# Defining the new df
top_10_schools = pd.DataFrame()
#Duplicating column of one df to another
top_10_schools['school_name'] = schools['school_name']
#Calculating new column with the sum of SAT scores in df
cols = ['average_math','average_reading','average_writing']
top_10_schools['total_SAT'] = schools[cols].sum(axis=1)
#Finding the top 10 schools with highest SAT scores
top_10_schools = top_10_schools.sort_values(by = 'total_SAT', ascending = False).head(10)
#Printing the resulting df
print(top_10_schools)# Defining the dataframe
largest_std_dev = pd.DataFrame()
# Calculating column for sum of SAT scores in schools df
cols = ['average_math', 'average_reading', 'average_writing']
schools['total_SAT'] = schools[cols].sum(axis=1)
# Calculate the standard deviation of 'total_SAT' for each borough
std_devs = schools.groupby('borough')['total_SAT'].std()
# Find the borough with the largest standard deviation
largest_std_dev_borough = std_devs.idxmax()
# Create a DataFrame with the borough having the largest standard deviation
largest_std_dev['borough'] = [largest_std_dev_borough]
# Calculating number of schools in the borough
largest_std_dev['num_schools'] = schools[schools['borough'] == largest_std_dev_borough]['school_name'].count()
# Calculating the mean of total SAT scores for the borough
largest_std_dev['average_SAT'] = schools[schools['borough'] == largest_std_dev_borough]['total_SAT'].mean().round(2)
# Calculating the standard deviation of total SAT scores for the borough
largest_std_dev['std_SAT'] = schools[schools['borough'] == largest_std_dev_borough]['total_SAT'].std().round(2)
# Printing the new df
print(largest_std_dev)