Pandas – One to Many Sort with Count

Question:

College Admin. trying to use Python to sort Final Grade Data to look at retention. Limited Experience Programming I have a data set that is set up by student, current score, course.

Example:

course                   current score                     grades

 Accounting                        65                           D

Accounting                          85                           B

Accounting                          87                           B

College Algebra                 95                           A

College Algebra                 90                           A

College Algebra                 91                           A

College Algebra                 25                           F

 

I was able to build conditions to set the grades column baed on current score to the corresponding letter grade. I am wondering how to sort/filter the data so it would isolate one instance of the course name with all of the letter grades counted.

For Example

Accounting                        A=0

                                      B=2

                                      C=0

                                      D=0

                                     F=0

 

College Algebra                 A=3

                                      B=0

                                      C=0

                                     D=0

                                     F=0

I would be grateful for any help or assistance. I cannot find the "wording" of how I would accomplish this. I was able to create a new column with letter grades based on the current score using numpy.

Asked By: Hank Hargis

||

Answers:

I would try using pandas as follows :

data.groupby(["course", "grades"]).count()
Answered By: rafidini
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.