Skip to content
Competition - exam scores
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
The file has the following fields (source):
- "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
- "reading" - exam score in reading
- "writing" - exam score in writing
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set_theme()
df = pd.read_csv('data/exams.csv')
df.head()๐ช Challenge
Create a report to answer the principal's questions. Include:
- What are the average reading scores for students with/without the test preparation course?
- What are the average scores for the different parental education levels?
- Create plots to visualize findings for questions 1 and 2.
- [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).
- [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.
- Summarize your findings.
1. What are the average reading scores for students with/without the test preparation course?
df['avg_score'] = (df['math'] + \
df['reading'] + \
df['writing']) / 3
df['test_prep_course'].unique()reading_average = df.groupby('test_prep_course')[['reading']].mean()
print('Average Test Score in reading with test preparion course: {}'.format(round(reading_average.iloc[0, 0], 2)))
print('Average Test Score in reading without test preparion course: {}'.format(round(reading_average.iloc[1, 0], 2)))
reading_average
2. What are the average scores for the different parental education levels?
avg_score_parent_education = df.groupby('parent_education_level')[['math', 'reading', 'writing', 'avg_score']].mean()
avg_score_parent_education.sort_values('avg_score', inplace=True, ascending=False)
avg_score_parent_education3. Create plots to visualize findings for questions 1 and 2.
ax = sns.barplot(data=df, x='test_prep_course', y='reading', ci=None)
ax.set_xlabel('Test preparation course')
ax.set_ylabel('Reading average score')
plt.show()ax = sns.barplot(data=avg_score_parent_education, x=avg_score_parent_education.index, y='avg_score')
ax.set_xlabel('Parent education level')
ax.set_ylabel('Average score')
ax.set_xticklabels(ax.get_xticklabels(),rotation = 45)
plt.show()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).
Let's start showing the scores grouped by parent education level and by preparation course.
avg_score = df.groupby(['parent_education_level', 'test_prep_course'])[['math', 'reading', 'writing', 'avg_score']].mean()
avg_scoreThere is no easy to vosualize the trend in the table, a visualization is shown below.
โ
โ
โ
โ
โ