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...
best_math_schools = schools[schools['average_math'] >= 0.8 * 800]
# Select only the 'school_name' and 'average_math' columns
best_math_schools = best_math_schools[['school_name', 'average_math']]
#Sort the DataFrame by 'average_math' in descending order
best_math_schools = best_math_schools.sort_values(by='average_math', ascending=False)
# Reset index to maintain a clean DataFrame
best_math_schools.reset_index(drop=True, inplace=True)
best_math_schools
import pandas as pd
# Assuming your original DataFrame is named 'df'
# Calculate the total SAT score for each school
schools['total_SAT'] = schools['average_math'] + schools['average_reading'] + schools['average_writing']
# Create a DataFrame with school name and total SAT score
top_10_schools = schools[['school_name', 'total_SAT']]
# Sort the DataFrame by total SAT score in descending order and select the top 10
top_10_schools = top_10_schools.sort_values(by='total_SAT', ascending=False).head(10)
# Reset index for a clean DataFrame
top_10_schools.reset_index(drop=True, inplace=True)
# Calculate standard deviation of total SAT scores for each borough
std_dev_by_borough = schools.groupby('borough')['total_SAT'].std().reset_index()
# Find the borough with the largest standard deviation
largest_std_dev_borough = std_dev_by_borough.loc[std_dev_by_borough['total_SAT'].idxmax()]
# Print the top 10 performing schools and the borough with the largest standard deviation
print("Top 10 Performing Schools:")
print(top_10_schools)
print("\nBorough with Largest Standard Deviation:")
print(largest_std_dev_borough)
largest_std_dev_borough = std_dev_by_borough.loc[std_dev_by_borough['total_SAT'].idxmax()]
# Filter the original DataFrame to get schools only from the borough with the largest standard deviation
schools_in_largest_borough = schools[schools['borough'] == largest_std_dev_borough['borough']]
# Calculate the number of schools in the borough
num_schools = len(schools_in_largest_borough)
# Calculate the mean and standard deviation of total SAT scores for the borough
average_SAT = schools_in_largest_borough['total_SAT'].mean()
std_SAT = schools_in_largest_borough['total_SAT'].std()
# Create a DataFrame with the required statistics
largest_std_dev = pd.DataFrame({
'borough': largest_std_dev_borough['borough'],
'num_schools': [num_schools],
'average_SAT': [round(average_SAT, 2)],
'std_SAT': [round(std_SAT, 2)]
})
# Print the DataFrame
print("DataFrame for the Borough with the Largest Standard Deviation:")
print(largest_std_dev)