this is the nav!
Analyzing Exam Performance
• AI Chat
• Code
• Report
• ## .mfe-app-workspace-kj242g{position:absolute;top:-8px;}.mfe-app-workspace-11ezf91{display:inline-block;}.mfe-app-workspace-11ezf91:hover .Anchor__copyLink{visibility:visible;}Analyzing exam scores

Now let's now move on to the competition and challenge.

### ðŸ“– Background

Your best friend is an administrator at a large school. The school makes every student take year-end math, reading, and writing exams.

Since you have recently learned data manipulation and visualization, you suggest helping your friend analyze the score results. The school's principal wants to know if test preparation courses are helpful. She also wants to explore the effect of parental education level on test scores.

### ðŸ’¾ The data

• "gender" - male / female
• "race/ethnicity" - one of 5 combinations of race/ethnicity
• "parent_education_level" - highest education level of either parent
• "lunch" - whether the student receives free/reduced or standard lunch
• "test_prep_course" - whether the student took the test preparation course
• "math" - exam score in math
• "writing" - exam score in writing

### ðŸ’ª Challenge

Create a report to answer the principal's questions. Include:

1. What are the average reading scores for students with/without the test preparation course?
2. What are the average scores for the different parental education levels?
3. Create plots to visualize findings for questions 1 and 2.
4. [Optional] Look at the effects within subgroups. Compare the average scores for students with/without the test preparation course for different parental education levels (e.g., faceted plots).
5. [Optional 2] The principal wants to know if kids who perform well on one subject also score well on the others. Look at the correlations between scores.
```.mfe-app-workspace-11z5vno{font-family:JetBrainsMonoNL,Menlo,Monaco,'Courier New',monospace;font-size:13px;line-height:20px;}```import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style('whitegrid')

pd.set_option('display.float_format', '{:,.2f}'.format)``````
``````df = pd.read_csv("data/exams.csv")
df.columns = ['gender', 'race', 'parent_education_level', 'lunch', 'test_prep_course', 'math', 'reading', 'writing']
``df['total'] = df['math'] + df['reading'] + df['writing']``

## Q1. What are the average reading scores for students with/without the test preparation course?

``````average_scores_test_prep = df.groupby("test_prep_course")['reading'].mean().reset_index()
average_scores_test_prep``````

## Q2. What are the average scores for the different parental education levels?

``````average_score_parents = df.groupby("parent_education_level")[['math','reading','writing']].mean().reset_index()
average_score_parents.columns = ['parent_background', 'avg_math', 'avg_reading', 'avg_writing']
average_score_parents_melt = pd.melt(average_score_parents, id_vars = 'parent_background', value_vars = ['avg_math', 'avg_reading', 'avg_writing'])
average_score_parents_melt.columns = ['parent_background', 'subject', 'score']
average_score_parents``````
``````average_score_parents['avg'] = average_score_parents.mean(axis = 1)
average_score_parents = average_score_parents.sort_values(by = 'avg', ascending = True)
sorted_categories = [
'some high school',
'high school',
'some college',
"associate's degree",
"bachelor's degree",
"master's degree"
]``````

## Q3. Create plots to visualize findings for questions 1 and 2.

``````fig, axs = plt.subplots(1, 2, figsize = (20, 6))

sns.barplot(data = average_scores_test_prep, x = 'test_prep', y = 'avg_reading_score', ax = axs[0], order = ['none', 'completed'])
sns.pointplot(data = average_score_parents_melt, x = 'parent_background', y = 'score', ax = axs[1], hue = 'subject', errorbar=('ci', 95), order = sorted_categories)

axs[0].set_title("Average test score based on test prep")
axs[1].set_title("Average score based on parent's educational attainment")

plt.legend(loc = 'upper left')
plt.tight_layout()``````

â€Œ
â€Œ
â€Œ