All problems

Students Above Their Major's Median GPA

hardPythonGroupByTransform

The dean's office at Ashgrove University is drawing up a departmental honours list. A single GPA cutoff was tried last year and it went badly: one major grades harder than the others, so a flat bar handed almost every place to the same department. This year the rule is relative — a student is judged against the typical student in their own major.

Three lists come out of that rule, and the office asks for them one at a time: the students who are above the typical student in their major, the students who are below, and the students sitting exactly on that point — the last being the borderline group that one reassessed paper could move either way. Which list is wanted comes with the request.

That makes the bar move. Every student is measured against a different number, and that number is set by the very rows they are being compared with.

students_df — one row per enrolled student. major is the department they belong to; gpa runs from 0.0 to 4.0.

id name major gpa
1 Nora Fischer Computer Science 3.8
2 Omar Haddad Statistics 3.4
3 Petra Novakova Computer Science 3.9
4 Quinn Walsh Mathematics 3.1
5 Ravi Shah Statistics 3.6

Input

The DataFrame above is already built for you — the student rows are not read from input. What does arrive is a single line holding one of three words: above, below, or on.

Task: Print an alphabetically sorted Python list of the names of the students whose GPA is strictly above, strictly below, or exactly equal to the median GPA of their own major, according to the word that arrives. The median is the middle value once that major's GPAs are put in order; if a major has an even number of students, it is the midpoint between the two middle values. Strictly means a student sitting exactly on their major's median belongs on the on list and on neither of the other two.

Example: if two students made the list, you'd print ['Ada Lovelace', 'Grace Hopper'].

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…