In services.py
Write a function, load_marks, that takes a file path, path, reads that csv file with pd.read_csv, and returns the DataFrame. Example:
>>> df = load_marks("data.csv")
>>> df.head(5)
student subject mark
0 Ana Math 78.0
1 Ana Science 85.0
2 Ana History NaN
3 Ana English 91.0
4 Ben Math 45.0
In services.py
Write a function, missing_marks, that takes the gradebook, df, and returns only the rows
where mark is missing. Example:
>>> df = load_marks("data.csv")
>>> missing_marks(df)
student subject mark
2 Ana History NaN
5 Ben Science NaN
11 Cleo English NaN
14 Dan History NaN
In services.py
A missed test counts as 0. Write a function, fill_missing, that takes df and returns a
new DataFrame where every missing mark is 0. Do not change df itself. Example:
>>> df = load_marks("data.csv")
>>> filled = fill_missing(df)
>>> filled.head(4)
student subject mark
0 Ana Math 78.0
1 Ana Science 85.0
2 Ana History 0.0
3 Ana English 91.0
In services.py
Write a function, average_by_student, that takes a gradebook with no missing marks, df,
and returns a Series with the average mark of each student. The student names are the labels.
Example:
>>> filled = fill_missing(load_marks("data.csv"))
>>> average_by_student(filled)
student
Ana 63.50
Ben 33.75
Cleo 68.75
Dan 31.50
Eli 63.25
Name: mark, dtype: float64
In services.py
Write a function, passing_students, that takes the Series of averages, averages, and returns
a list with the names of the students whose average is at least 50, in the same order as
averages. Example:
>>> averages = average_by_student(fill_missing(load_marks("data.csv")))
>>> passing_students(averages)
['Ana', 'Cleo', 'Eli']
In main.py
Write a function, print_report, that takes a file path, path, and prints the report for
Ms. Hoxha: the number of missing marks, the averages (fill missing marks with 0 first), and the
students who passed. Use the functions you wrote in services.py. Then call
print_report("data.csv"). Running main.py should print:
Missing marks: 4 student Ana 63.50 Ben 33.75 Cleo 68.75 Dan 31.50 Eli 63.25 Name: mark, dtype: float64 Passed: Ana, Cleo, Eli
Project Structure
No file selected