Learning Task: upload data to colab and read data python exploratory analysis

In [ ]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [ ]:
#read data
df = pd.read_csv('student.csv')
df.head(10) #deafult is 5, we put in 10 to see top 10 rows if data.. df.tail() to see last rows of data
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
5 female group B associate's degree standard none 71 83 78
6 female group B some college standard completed 88 95 92
7 male group B some college free/reduced none 40 43 39
8 male group D high school free/reduced completed 64 64 67
9 female group B high school free/reduced none 38 60 50
In [ ]:
# check out the data type for each column
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 [ ]:
#explore data types
df['parental_education'] = df['parental_education'].astype('category') # how to change data types
df.dtypes
Out[ ]:
0
gender object
ethnicity object
parental_education category
lunch object
test_preparation_course object
math_score int64
reading_score int64
writing_score int64

In [ ]:
#changing more than one datatype at a time. you need double brackets
df[['math_score', 'reading_score', 'writing_score']] = df[['math_score', 'reading_score', 'writing_score']].astype(float)
df.dtypes
Out[ ]:
0
gender object
ethnicity object
parental_education category
lunch object
test_preparation_course object
math_score float64
reading_score float64
writing_score float64

In [ ]:
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.0 72.0 74.0
1 female group C some college standard completed 69.0 90.0 88.0
2 female group B master's degree standard none 90.0 95.0 93.0
3 male group A associate's degree free/reduced none 47.0 57.0 44.0
4 male group C some college standard none 76.0 78.0 75.0
In [ ]:
#counts the number of rows, not including the header
len(df)
Out[ ]:
1000
In [ ]:
#check how many classes/label are within 'parental_education'
df['parental_education'].value_counts()
Out[ ]:
count
parental_education
some college 226
associate's degree 222
high school 196
some high school 179
bachelor's degree 118
master's degree 59

In [ ]:
#create a visual to better explore the data distribution
sns.countplot(data= df, x= 'parental_education', hue= 'parental_education')
plt.xticks(rotation= 20) #bends the bottom names
plt.show()
No description has been provided for this image
In [ ]:
#explore the distribution of scores across gender
sns.scatterplot(data=df, x='reading_score', y= 'math_score', hue = 'gender') #look at correlation
sns.kdeplot(data=df, x='reading_score', y='math_score', hue= 'gender',
            levels=4)
plt.show()
No description has been provided for this image
In [ ]: