Feat: Minor thing
This commit is contained in:
@@ -8,6 +8,12 @@ from .config import NO_ST_COLUMNS, COLUMNS, VALIDSCORE
|
||||
|
||||
pd.set_option("Precision", 2)
|
||||
|
||||
def try_replace(x, old, new):
|
||||
try:
|
||||
return str(x).replace(old, new)
|
||||
except ValueError:
|
||||
return x
|
||||
|
||||
|
||||
def extract_students(df, no_student_columns=NO_ST_COLUMNS.values()):
|
||||
""" Extract the list of students from df
|
||||
@@ -44,9 +50,9 @@ def flat_df_students(df, no_student_columns=NO_ST_COLUMNS.values()):
|
||||
value_vars=st,
|
||||
var_name=COLUMNS["student"],
|
||||
value_name=COLUMNS["score"],
|
||||
)
|
||||
).dropna(subset=[COLUMNS["score"]])
|
||||
)
|
||||
return pd.concat(scores).dropna(subset=[COLUMNS["score"]])
|
||||
return pd.concat(scores)
|
||||
|
||||
|
||||
def flat_clear_csv(csv_df, no_student_columns=NO_ST_COLUMNS.values()):
|
||||
@@ -67,11 +73,12 @@ def flat_clear_csv(csv_df, no_student_columns=NO_ST_COLUMNS.values()):
|
||||
df[COLUMNS["score"]] = pd.to_numeric(
|
||||
df[COLUMNS["score"]]
|
||||
.replace(VALIDSCORE["NOANSWER"], -1)
|
||||
.apply(lambda x: str(x).replace(",", "."))
|
||||
.apply(lambda x: try_replace(x, ",", "."))
|
||||
)
|
||||
df[COLUMNS["score_rate"]] = pd.to_numeric(
|
||||
df[COLUMNS["score_rate"]]
|
||||
.apply(lambda x: str(x).replace(",", "."))
|
||||
.apply(lambda x: try_replace(x, ",", ".")),
|
||||
errors="coerce"
|
||||
)
|
||||
|
||||
return df
|
||||
|
||||
@@ -77,14 +77,14 @@ def score_to_level(x):
|
||||
>>> score_to_level(df.loc[10])
|
||||
2
|
||||
"""
|
||||
# -1 is no answer
|
||||
if x[COLUMNS["score"]] == -1:
|
||||
return x[COLUMNS["score"]]
|
||||
# negatives are no answer or negatives points
|
||||
if x[COLUMNS["score"]] <= -1:
|
||||
return np.nan
|
||||
|
||||
if x[COLUMNS["is_leveled"]]:
|
||||
return int(x[COLUMNS["score"]])
|
||||
else:
|
||||
return int(ceil(x[COLUMNS["score"]] / x[COLUMNS["score_rate"]] * 3))
|
||||
|
||||
return int(ceil(x[COLUMNS["score"]] / x[COLUMNS["score_rate"]] * 3))
|
||||
|
||||
|
||||
# DataFrame columns manipulations
|
||||
|
||||
Reference in New Issue
Block a user