Skip to content

Exploring NYC Public School Test Result Scores

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.

  1. Import pandas library
  2. Read datafile
  3. Preview data
import pandas as pd 
import numpy as np

# Read in the data
schools = pd.read_csv("schools.csv")

# Preview the data
schools.head()

What are the top 10 schools in math above 80% score?

Subsetting data by the column 'average_math' to be greater than the 80% of the total 800 points score with >0.8*800

Then just show head of the data head(10)

df1 = schools[schools['average_math']>0.8*800]
best_math_schools= df1[["school_name","average_math"]].sort_values(by='average_math',ascending=False)
best_math_schools.head(10)

Create a new column that stores the total SAT score by adding the 3 score categories. 'average_math','average_reading', 'average_writing'

Filter the data by the top 10 schools with the highest SAT score

schools['total_SAT'] = schools['average_math']+schools['average_reading']+schools['average_writing'] #Creating new column
top_10_schools = schools[['school_name','total_SAT']].sort_values(by='total_SAT',ascending=False) #Order dataset
top_10_schools = top_10_schools.iloc[:10]
top_10_schools

What is the borough with the most SAT score, how many schools does it have and what is its average and standard deviation SAT score?

  1. The dataframe is grouped by borough and then calculate 'std' and 'max' with function '.agg' of the column 'total_SAT'
  2. Find the index borough with the max standard deviation. With the function 'idxmax()'
  3. Create a dataframe with the 5 required columns and with its value ['borough','number of schools'.'average SAT','standard deviation', maximum SAT] with values rounded to 2 digits.
borough = schools.groupby('borough')['total_SAT'].agg(['std','max'])
max_std_borough = borough['std'].idxmax()

# Create a new DataFrame with the required information
largest_std_dev = pd.DataFrame({
    'borough': max_std_borough,
    'num_schools': schools[schools['borough'] == max_std_borough].shape[0],
    'average_SAT': schools[schools['borough'] == max_std_borough]['total_SAT'].mean(),
    'std_SAT': max_std_stats['std'],
    'max_SAT':[ max_std_stats['max']]
})
# Round all values to 2 digits
largest_std_dev = largest_std_dev.round(2)
largest_std_dev