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()
Exploring DataFrame
# with .shape
schools.shape
# with .info()
schools.info()
# with .describe()
schools.describe()
# with .columns
schools.columns
# with .index
schools.index
Question N1: Which NYC schools have the best math results?
## Creating a list of columns to subset
cols_to_subset = ["school_name","average_math"]
## Subsetting math score by school
math_score_by_school=schools[cols_to_subset]
## Filtering school with best result in Math( 80% of the maximum score 800)
best_math_score_greater_80Percent = math_score_by_school[math_score_by_school["average_math"] >= (800*80/100)]
## Sorting the best Math school in descending order
best_math_schools = best_math_score_greater_80Percent.sort_values("average_math", ascending=False)
## print (best_math_schools)
Question N2: What are the top 10 performing schools based on the combined SAT scores?
## Calculating the Total SAT in new columns
schools["total_SAT"]=schools["average_math"] + schools["average_reading"] \
+ schools["average_writing"]
## Creating a list of columns to subset
cols_to_subset_total_SAT = ["school_name","total_SAT"]
## Subsetting math score by school
school_total_SAT = schools[cols_to_subset_total_SAT]
## Sorting the best total_SAT school in descending order
school_total_SAT_sorted = school_total_SAT.sort_values("total_SAT", ascending=False)
## top 10 schools with total_SAT
top_10_schools = school_total_SAT_sorted.head(10)
top_10_schools
Question N3:Which single borough has the largest standard deviation in the combined SAT score?
## Group data by borough and calculating number of schools, average SAT and standard deviation for each group
group_by_borough = schools.groupby("borough")["total_SAT"].agg(num_schools = "count", average_SAT = "mean", std_SAT = "std")
## Rounding all numerical value to two decimal places
group_by_boroug_rounded = group_by_borough.round(2)
## transforming result into dataframe
df_borough = group_by_boroug_rounded.reset_index()
## Renaming the columns
## df_borough = df_borough.rename(columns = {"count":"num_schools","mean": "average_SAT","std": "std_SAT"})
## Sorting by std_SAT
std_SAT_sorted = df_borough.sort_values("std_SAT", ascending=False)
# Filtering the largest standard deviation in Borough
largest_std_dev = std_SAT_sorted.head(1)
largest_std_dev
Question N3: Second Solution