Grouping the Data to Calculate Final Scores
00:00 To compute the final grade, let’s first define the weights that we’ll use in the final computation. We’ll use a Series for this, and we’re going to name the keys in the dictionary that we’ll pass in.
00:17 These are going to serve as the index for the Series. We want to name them exactly as we’ve named the columns in the DataFrame that store the exam scores, the homework score, and the quiz score.
01:32 because these are the columns that we need. Exam 1, 2, 3, quiz score, and homework score. Then we simply multiply them by the weights, and so these are just going to be these numbers that are less than 1.
Let’s call this, say, in the final DataFrame. We’ll introduce a new column and this will simply be, say,
'Final Score'. All right. Now, likely we’re going to want to input these scores by putting in an integer and not a decimal number, not something less than one.
02:58 Now, it’s likely that once we have these ceiling scores, or these rounded scores, we need to compute a letter grade, which will actually be the final data that we’re going to have to input in some sort of system at, say, the registrar’s office.
Now, so that we can later plot and maybe compare letter grades if we wanted to do some sort of visualization of letter grades—say, from
'A'—and we wanted these to be ordered or to be interpreted as being ordered, because, you know, usually we would think of
'A' as being the highest grade and
'B' is the second highest grade, and so on, when we actually add this to our main DataFrame, we want to do this by adding a
Categorical series, and so let’s define sort of a temporary
letter_grades Series. And then in our main DataFrame, we’re going to add one more column called
'Final Grade', and this is going to be a
Now, a category may not necessarily have an order. So, for example, if the data was on colors and the colors were maybe, you know, red, green, blue, and whatever, then these wouldn’t necessarily have some sort of order to them, although they possibly could depending on your application. But in this case, the letter grades are ordered.
'F' is usually considered the lowest grade, and then
There is a keyword argument called
ordered and the default is
False but we actually, in this case, want it to be
True because we do want the values of this series to be interpreted or have a relationship of being ordered.
with all of the grades, we see that we’ve got a data type as
category, we’ve got all the letter grades, and the lowest grade is
'F', and then
'A'. So for the purposes of computing the final grade for each student, this pretty much does it.
07:22 We’ll have to do this, possibly, via section. We have all of these students and there are three sections, and so maybe the last thing that we want to do is to create CSV files containing the grades for each of the individual sections.
Become a Member to join the conversation.