919723, 643 PM Unilea22-Copy6-- Jupyter Notebook
Analyzing student performance in exams using Python
‘Analyzing Student Performance in Exams with Python" is a Jupyler Notebook that explores and visualizes student
‘exam data using Python. This notebook provides a comprehensive analysis of student scores, including statistical
insights, data visualization, and potentially machine learning techniques to identily patterns and trends in student
performance. It serves as a valuable tool for educators, researchers, and anyone interested in understanding and
improving educational outcomes.
Import Library
tn [1]: import pandas as pd
In [2]: import pandas as pd
inport seaborn as sns
Anport matplotlib.pyplot as plt
import seaborn as sns
C:\Users\syed ari f\anaconda3\1ib\site-packages\scipy\_init,
+py:146: Userwarning: A NunPy versi
116.5 and <1,23.0 is required for this version of Scify (detected version 1.25.1
warnings.warn(f"A NunPy version >=np_minversion} and <{np_raxversion}"
Uploading Csv fle
In [3]: df = pd.read_esv(r°C:\Users\Syed Arif\Dounloads \Conpressed\Top 5@ Accounts\StudentsPerformance.cs\
Data Preprocessing
-head()
head is used show to the By default = 5 rows in the dataset
In [4]: df-head()
outa]
crv comity Paminet ney totowrgin thea
ctail()
{ail is used to show rows by Descending order
locahost 8888/natebooks/Untiled22-Copy6 ipyno wm919723, 643 PM Unilea22-Copy6-- Jupyter Notebook
In [5]: af.tail()
out [5]
gender racelethnicty —Pavertayievelet junc fest Preparatior Linens eed
885 female goupE ——maslaredagroo standard comptes = %
296 me grupo hign scree! reoteduend one 82 55 ss
997 female grup high schoo feetedueea comptes 58 n ts
808 female grupo some colege sandr comptes 58 7% n
899 female grup some colege Hreetedueed one 7? os a
-Shape
It show the total no of rows & Column inthe dataset
In [6]: df.shape
ute}: (1000, 8)
-Columns
It show the no of each Column
In [7]: 4f.columns
Out 7]: Index({'gender*, ‘race/ethnicity’, ‘parental level of education’, ‘Lunch’,
‘test preparation course’, “math score’, ‘reading score’,
swriting score’),
dtypes object")
.dtypes
‘This Attrbute show the data type of each column
In [8]: df.dtypes
out [8]: gender object
race/ethnicity object
parental level of education object.
lunch object
‘test preparation course object
rath score intea
reading score intea
writing score intea
dtype: object
-unique()
Ina column, It show the unique value of specific column.
locahost 8888/natebooks/Untiled22-Copy6 ipyno ant919723, 643 PM
In [9]:
out [9]
In [18]
out 19]
In [1a]:
outta]:
In [12]
out(22]
Unilea22-Copy6-- Jupyter Notebook
f["lunch"] .unique()
array([‘standard', ‘free/reduced'], dtypesobject)
-nuique()
Itwil show the total no of unque value from whole data frame
f.nunique()
gender 2
race/ethnicity 5
parental level of education 6
lunch 2
‘test preparation course 2
math score a
reading score n
writing score n
dtype: intoa
-describe()
It show the Count, mean , median ete
aF.deseribe()
math score reading score writing score
‘count 7000.00000 1000.000000 1000.000000,
mean 66.08000 69.160000 #054000
std 15,6908 +4.600192 —16.195657
min 0.00000 +7,000000 10.000000
25% s7.00000 $9.000000 _57:750000
50% 66.0000 70.000000 9.000000
75% 7.00000 79,0000 79.000000
max 100.0000 100,000000 :00,000000,
-value_counts
It Shows all the unique values with thelr count
¢["gender"].value_counts()
fenale 518
role 482
Name: gender, dtype: inted
isnull()
It shows the how many null values
locahost 8888/natebooks/Untiled22-Copy6 ipyno
ant919723, 643 PM
Unilea22-Copy6-- Jupyter Notebook
In [13]: df.dsnull()
out [13]
Sender racelethnicty Peremtucation neh ee score ocure—"eore
o Fate Fae Fate False Fae ‘Fae Fase Fae
+ Fane False Felco False Fate Fate Fao Fate
2 Fale False False False False Feae Fase Fea
a Fate False False False False Fale Foe False
4 Fae Fee Fro False Foleo Fao Fake Fate
95 Fao False Flee False Fase Fase Fase aise
206 Fale False False False Fase Fase alse
oor Fate Fl Free False Fase False
00 Fate Fee Frce False Fate Fake Faso
09 Fate False Frise False Foie Fee Fase Fee
1000 rows * 8 columns
In [14]: df.isnull().sum()
Out[14]: gender e
race/ethnicity °
parental level of education 0
Tunch 8
‘test preparation course °
nath score @
reading score °
writing score °
type: inte
How many Null value present show all the null values in
Heatmap
locanos: 88tinctebook/Untleg22-Copy® py ain919723, 643 PM Unilea22-Copy6-- Jupyter Notebook
In [45]: sns-heatmap(dF.isnull())
ple. show()
0100
07s
00s
acs
cose
. ae a
: a
i z
E
a
Data Visualization
Performance Overview
In [16]: preparation =(len(df[d#['test preparation course'] == ‘completed']) / len(df)) * 100
preparation
Out[16]: 35.8
Calculate average math Score
In [17]: average_score = dff'nath score’ ].mean()
average score
out [17]: 66.089
Calculate the preparation course & Show in Barplot
locahost 8888/natebooks/Untiled22-Copy6 ipyno919723, 643 PM Unilea22-Copy6-- Jupyter Notebook
In [18]: df["test preparation course’ ].value_counts().plot(kind = “bar")
ut [18]:
8B e288
In [19]: pLt.figure(figsize=(2, 6))
sns.countplot(data=dF, x='gender', hue='test preparation course’)
plt.xlabel (‘gender’)
plt.ylabel('test preparation course’)
plt.title( "Course Completion by Gender’)
plt.show()
Course Completion by Gender
‘est preparation course
fm competed
350
gender
Calculate the lunch type and show the values using
Borplot
locahost 8888/natebooks/Untiled22-Copy6 ipyno
on979/29, 649 PM Uniled22-Copy6 - Jupyter Notebook
In [20]: df[‘Iunch*].value_counts().plot(kind = “bar*)
ut [20]:
Bee e288
stondars
seetreavced
In [21]: df["Lunch*] .value_counts()
out[21]: standard 64s
free/reduced 355
Name: lunch, dtype: intea
Show the lunch type by gender wise
In [22]: lunch avg_gender = dF.groupby(" lunch" )[ gender’ ].value_counts().plot (kin
unch_ave_gender
©
eB See gs
(ctandar, male)
(reereduce, female)
(Wreereduced, mal)
(ctandad, fea)
lunchgender
Calculate average scores by gender in reading Score
localhost 8888/natebooks/Untiled22-Copy6 ipyno mm919723, 643 PM
In [23]:
out 23]:
In [24]:
out (24)
In [25]
Unilea22-Copy6-- Jupyter Notebook
gender_avg_scores = df.groupby(‘gender')[ ‘reading score" ].mean()
gender_avg_scores
gender
fenale — 72.608108,
nale 65.473029
Nane: reading score, dtype: floats
F. gender. value_counts().plot(kind = “bar*)
0
x00
female
smote
Calculate average by gender in level of education Score
Level_edu = df[*parental level of education" J.value_counts()
level_edu
sone college 226
associate's degree 222
high school 196
sone high school 179
bachelor’s degree 118,
naster's degree 59
Nane: parental level of education, dtype: intea
Show the level of education Using Barplot
locahost 8888/natebooks/Untiled22-Copy6 ipyno an979/29, 649 PM Uniled22-Copy6 - Jupyter Notebook
In [26]: df["parental level of education’ J.value_counts().plot(kind = “bar")
ut [26]:
college
ossoclate’s degree
igh schoo!
bochelor's degree
rosters degree
same high seneo!
In [27]: level_gender = df.groupby('parental level of education')f' gender’ ].value_counts() .plot(kind = "ba
level_gender
Out[27]:
“TEPLLLL ALTE
PEE EE EL
aiggeequadrl
piga "ileal
parental level of edueton gender
locahost 8888/natebooks/Untiled22-Copy6 ipyno oitt919723, 643 PM Unilea22-Copy6-- Jupyter Notebook
In [20]: plt.figure(Figsize=(#, 6))
sns.countplot (data=dF,
plt.xlabel (‘gender’)
plt.ylabel('parental level of education’)
plt.title("level of education by Gender")
plt.show()
level of education by Gender
‘gender’, hue="parental level of education’)
‘parental evel af education
me bachelors degree
some cotege
masters degree
socite's degree
high choot
some hi schoo
parental evel education
gender
Test Preparation Course
Calculate students who completes the test proparation course
In [28]: df[d¢['test preparation course" ]
‘conpleted"]
out (28):
der raceitiicty PM icaton func tr “net "tes
7 woe ‘ome oalege standard compa ~~ ~ =
‘ ups some clege sana completes 88 6 2
‘ up high seo! teareduced comptes ot o or
13 mile ap some colege sandal comptes 78 n 10
18 male group master aor frnredces completed 48 2 “6
ty up high schoo! rearedueed comptes 6 e %
S81 female group B_——some hin school standard comptes 88 cy 7
905 female group ——mastarscemree standart comptes 88 * %5
S87 female grup high schol reateduced completed «50 n «6
208 fom grup some clege sande competed 88 Ey 7
358 rows x 8 columns
nth:
locanos: 88tinctebook/Untleg22-Copy® py sats919723, 643 PM Unilea22-Copy6-- Jupyter Notebook
localhost 868/notebooks/Untilea22-Copy6 ipyno na