"""
This note is trying to answer the following questions:

Q1: Effect of gender and education level on average score.
Q2: Effect of gender and preparation on average score.
Q3: Which group is the most Successful?
"""
#Importing Libraries
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

#Load DataSet
my_data = pd.read_csv("../input/stuperformance/StudentsPerformance_DataSet.xls")
df = my_data.copy()
#Checking the data
df.info()
#Look at heed
df.head()
#Renaming Columns 
df.rename(inplace = True,
           columns={"race/ethnicity":"race_ethnicity",
                   "parental level of education":"Education_level",
                   "test preparation course":"prep_course",
                   "math score":"math_score",
                   "reading score":"reading_score",
                   "writing score":"writing_score"})
#Creating a new column average score
df['average_score'] = df[['math_score', 'reading_score', 'writing_score']].mean(axis=1)
df.head()
df.describe().T
#Assigning Grades
def Grade(AverageScore):
    if(AverageScore >= 80):return 'A'
    if(AverageScore >= 70):return 'B'
    if(AverageScore >= 60):return 'C'
    if(AverageScore >= 50):return 'D'
    if(AverageScore >= 40):return 'E'
    else: return 'F'
    
df["grade"] = df.apply(lambda x : Grade(x["average_score"]), axis=1)
    
#Pie Chart Showing the grade Distribution
plt.figure(figsize=(7,7))
plt.pie(df['grade'].value_counts().values,
       labels=df['grade'].value_counts().index,
       autopct='%1.1f%%',
       shadow=True,
       explode=[0,0,0.1,0,0,0])
plt.title('Grand Pie Chart', color='Black', fontsize=20)
plt.show()
#Look at the Score
plt.figure(figsize=(7,7))
plt.title('Score Heatmap', color='Black', fontsize=20,pad=40)
sns.heatmap(df.corr(),annot=True,linewidths=.5);
#Answer to question no 1
sns.catplot(data=df, x="gender", y="average_score", hue="Education_level",kind="bar", height=5 )
#Answer to question no. 2
sns.catplot(data=df, x="gender", y="average_score", hue="prep_course",kind="bar",height=5);
#Answer to question no.3
sns.barplot(x='race_ethnicity',y='average_score',data=df);
df.groupby("race_ethnicity")["average_score"].mean()
df.groupby("race_ethnicity")['Education_level'].describe()
df.groupby("race_ethnicity")['prep_course'].describe()
df.groupby('race_ethnicity')['grade'].describe()
(sns.FacetGrid(df,hue="race_ethnicity",height=5,xlim=(0,100)).map(sns.kdeplot, "average_score").add_legend())
sns.catplot(x="race_ethnicity", y="average_score", hue="grade", kind="point", data=df);
"""
* **Comment. Waiting for feedback**
"""