In [ ]:
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
In [ ]:
df= pd.read_csv('student.csv')
df.head()
Out[ ]:
gender ethnicity parental_education lunch test_preparation_course math_score reading_score writing_score
0 female group B bachelor's degree standard none 72 72 74
1 female group C some college standard completed 69 90 88
2 female group B master's degree standard none 90 95 93
3 male group A associate's degree free/reduced none 47 57 44
4 male group C some college standard none 76 78 75
In [ ]:
#1. Upload the dataset to Google Colab and change the "test_preparation_course" into categorical variable.
df.dtypes
Out[ ]:
0
gender object
ethnicity object
parental_education object
lunch object
test_preparation_course object
math_score int64
reading_score int64
writing_score int64

In [ ]:
df['test_preparation_course'] = df['test_preparation_course'].astype('category') # how to change data types
df.dtypes
Out[ ]:
0
gender object
ethnicity object
parental_education object
lunch object
test_preparation_course category
math_score int64
reading_score int64
writing_score int64

In [ ]:
#2. Use value_counts() function to find out the how many students
#participated the "test_preparation_course" and how many did not.
df['test_preparation_course'].value_counts()
Out[ ]:
count
test_preparation_course
none 642
completed 358

In [ ]:
#3. Let's create a data visualization by using Python.
#Create a histogram to show the distribution of "reading_score".
In [ ]:
plt.figure(figsize=(4,3))
sns.histplot(data= df, x= 'reading_score', kde=True, color= '#d62828',
             binwidth= 5)
plt.show()
No description has been provided for this image
In [ ]:
#4 Create a new data frame called df_new. In this data frame,
#you need to transform two variables (gender & test_preparation_course)
#to dummy variables and drop first columns.
In [ ]:
df_new = pd.get_dummies(df, columns=['gender', 'test_preparation_course'],
                        dtype=int, drop_first=True)
df_new.head()
Out[ ]:
ethnicity parental_education lunch math_score reading_score writing_score gender_male test_preparation_course_none
0 group B bachelor's degree standard 72 72 74 0 1
1 group C some college standard 69 90 88 0 0
2 group B master's degree standard 90 95 93 0 1
3 group A associate's degree free/reduced 47 57 44 1 1
4 group C some college standard 76 78 75 1 1
In [ ]:
!jupyter nbconvert --to html bana410_Homework1.ipynb
[NbConvertApp] Converting notebook bana410_Homework1.ipynb to html
[NbConvertApp] WARNING | Alternative text is missing on 1 image(s).
[NbConvertApp] Writing 323039 bytes to bana410_Homework1.html
In [ ]: