title: Convert a letter grade to a GPA: What is wrong with my code?
body: <p>I have a dataframe, df, similar to the one below.  </p>
  
  <pre><code>ID       SUBJ           GRADE
  
  1   Amer Natl Govt      A
  2   Princ Of Macroecon  B
  3   General Biology     B
  4   Concept Of Chem     C
  5   General Chem        C
  </code></pre>
  
  <p>I’d just like to convert the letter grade (GRADE) to a grade-point average. </p>
  
  <p>I’ve written the following code, which always returns the exception, 2.3 for all rows, as if the datatype of the letter in my list of tuples is of a different type than that in my dataframe, but they are both strings.  Could someone tell me the problem with my code? Thank you.</p>
  
  <pre><code>def getGradePoint(row):
  
      grades = [('A+', 4.0), ('A', 4.0), ('A-', 3.7), ('B+',3.3), ('B',3.0), ('B-',2.7), ('C+',2.3), ('C',2.0),\
            ('C-',1.7),('D+',1.3),('D',1.0),('D-',0.7),('F',0.0)]
      for i in range(len(grades)):
           if row == grades[i][0]:
               return grades[i][1]
           else:
               return 2.3
  
  df['GRADE_PT'] = df['GRADE'].apply(getGradePoint)   
  
  ID       SUBJ           GRADE    GPA
  
  1   Amer Natl Govt      A        2.3
  2   Princ Of Macroecon  B        2.3
  3   General Biology     B        2.3
  4   Concept Of Chem     C        2.3
  5   General Chem        C        2.3
  </code></pre>