1

I am trying to make a gradebook in python. The code reads an excel file consisting of student ID numbers, the corresponding name, and the corresponding assignment grades. The code already sums the total points and gives the correct corresponding letter grade. However, I am trying to produce a histogram in the style of a bar plot. As such, I am having trouble converting letter grades to bins. (Numpy bincount and digitize require numbers rather than strings).

As an example, consider a small class of 5 students. The breakdown on grades to points is as follows:

letter grade:  F 
 score borders:  0.00 - 100.00


letter grade:  D- 
 score borders:  100.00 - 108.64


letter grade:  D 
 score borders:  108.64 - 117.27


letter grade:  D+ 
 score borders:  117.27 - 125.91


letter grade:  C- 
 score borders:  125.91 - 134.55


letter grade:  C 
 score borders:  134.55 - 143.18


letter grade:  C+ 
 score borders:  143.18 - 151.82


letter grade:  B- 
 score borders:  151.82 - 160.45


letter grade:  B 
 score borders:  160.45 - 169.09


letter grade:  B+ 
 score borders:  169.09 - 177.73


letter grade:  A- 
 score borders:  177.73 - 186.36


letter grade:  A 
 score borders:  186.36 - inf # extra credit

As per the example, the information and grades of the 5 students are as follows:

Student ID:        1830  
Student Score:    195.50    
Class Grade:          A  


Student ID:        5000  
Student Score:    174.50    
Class Grade:          B+  


Student ID:        9000  
Student Score:    162.00    
Class Grade:          B  


Student ID:        327  
Student Score:    118.00    
Class Grade:          D+  


Student ID:        9434  
Student Score:    191.00    
Class Grade:          A  

Each letter grade is chronologically placed in final_grades. To count the number of occurrences of each letter grade, I know that I can use Counter via Collections.

cc = Counter(final_grades)
print(cc)
>> Counter({'A': 2, 'B': 1, 'B+': 1, 'D+': 1})

for ci in cc:
    print(cc[ci])
>> 1
>> 2
>> 1
>> 1

I've looked at this stack overflow example to deal with the order of the letter grades is not maintained in dictionaries. However, my main issue is using that I wanted to return 0 counts for grades not included. So for example, I want the full list of all letter grades, in which case it should show 'C': 0 (alongside the other letter grades).

What are some approaches to tackle this problem? (So far, my best idea, which I don't like, is to convert each letter grade to a number and use numpy bincount).

0 Answers0