add normalized column into digest_flat_df

This commit is contained in:
Benjamin Bertrand 2016-11-13 14:40:36 +03:00
parent dc8f3804a6
commit ec469214da

View File

@ -69,6 +69,8 @@ def note_to_mark(x):
def compute_marks(df): def compute_marks(df):
""" Add Mark column to df """ Add Mark column to df
:param df: DataFrame with "Note", "Niveau" and "Bareme" columns.
>>> d = {"Eleve":["E1"]*6 + ["E2"]*6, >>> d = {"Eleve":["E1"]*6 + ["E2"]*6,
... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2, ... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2,
... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"], ... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"],
@ -100,6 +102,8 @@ def compute_marks(df):
def compute_latex_rep(df): def compute_latex_rep(df):
""" Add Latex_rep column to df """ Add Latex_rep column to df
:param df: DataFrame with "Note" and "Niveau" columns.
>>> d = {"Eleve":["E1"]*6 + ["E2"]*6, >>> d = {"Eleve":["E1"]*6 + ["E2"]*6,
... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2, ... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2,
... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"], ... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"],
@ -128,6 +132,40 @@ def compute_latex_rep(df):
""" """
return df[["Note", "Niveau"]].apply(note_to_rep, axis=1).fillna("??") return df[["Note", "Niveau"]].apply(note_to_rep, axis=1).fillna("??")
def compute_normalized(df):
""" Compute the normalized mark (Mark / Bareme)
:param df: DataFrame with "Mark" and "Bareme" columns
>>> d = {"Eleve":["E1"]*6 + ["E2"]*6,
... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2,
... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"],
... "Question":["Q1"]+["Q2"]+["Q1"]+["Q2"]+["Q1"]+["Q1"] + ["Q1"]+["Q2"]+["Q1"]+["Q2"]+["Q1"]+["Q1"],
... "Date":["16/09/2016"]*4+["01/10/2016"]*2 + ["16/09/2016"]*4+["01/10/2016"]*2,
... "Trimestre": ["1"]*12,
... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2,
... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2,
... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.666, 1, 1.5, 1, 2, 3],
... }
>>> df = pd.DataFrame(d)
>>> df["Mark"] = compute_marks(df)
>>> compute_normalized(df)
0 1.000000
1 0.330000
2 1.000000
3 0.750000
4 0.333333
5 1.000000
6 0.666000
7 1.000000
8 0.750000
9 0.500000
10 0.666667
11 1.000000
dtype: float64
"""
return df["Mark"] / df["Bareme"]
# Computing custom values # Computing custom values
def compute_exo_marks(df): def compute_exo_marks(df):
@ -229,9 +267,12 @@ def digest_flat_df(flat_df):
df = flat_df.copy() df = flat_df.copy()
df["Mark"] = compute_marks(flat_df) df["Mark"] = compute_marks(flat_df)
df["Latex_rep"] = compute_latex_rep(flat_df) df["Latex_rep"] = compute_latex_rep(flat_df)
df["Normalized"] = compute_normalized(flat_df)
exo_df = compute_exo_marks(df) exo_df = compute_exo_marks(df)
exo_df["Normalized"] = compute_normalized(exo_df)
eval_df = compute_eval_marks(exo_df) eval_df = compute_eval_marks(exo_df)
eval_df["Normalized"] = compute_normalized(eval_df)
return df, exo_df, eval_df return df, exo_df, eval_df