In [ ]:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
In [ ]:
# create a simple pie chart
prod= [500, 300]
prod_name= ['iphone', 'ipad']
color= ['#ccdbfd', '#f4845f']
In [ ]:
#visualize the pie chart
plt.figure(figsize=(4,4))
plt.pie(prod, labels=prod_name, colors=color)
plt.show()
No description has been provided for this image
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 [ ]:
#visualize gender distribution via pie chart
gender_count= df['gender'].value_counts()
gender_count
Out[ ]:
count
gender
female 518
male 482

In [ ]:
#extract labels
names= df['gender'].value_counts().index.tolist()
names
Out[ ]:
['female', 'male']
In [ ]:
#extract numbers
values= df['gender'].value_counts().tolist()
values
Out[ ]:
[518, 482]
In [ ]:
colors=['#fc809f','#1976d2']
In [ ]:
#visualize the pie for gender distribution
plt.figure(figsize=(4,4))
plt.pie(values, labels=names, colors=colors)
plt.show()
No description has been provided for this image
In [ ]:
#pie chart for ethnicity
ethnicity_count= df['ethnicity'].value_counts()
ethnicity_count
Out[ ]:
count
ethnicity
group C 319
group D 262
group B 190
group E 140
group A 89

In [ ]:
#pie for ethnicity
ethnicity= df['ethnicity'].value_counts().index.tolist()
ethnicity
Out[ ]:
['group C', 'group D', 'group B', 'group E', 'group A']
In [ ]:
colors=['blue','red', 'green', 'orange', 'brown']
In [ ]:
plt.figure(figsize=(6,6))
plt.pie(ethnicity_count, labels=ethnicity, colors=colors, autopct= '%1.2f%%')
plt.show()
No description has been provided for this image
In [ ]: