Adjusting student GPAs based on attendance levels in Python

Question

Suppose you're looking to offer a small boost to the grades of Engineering students based on attendance. If students attended class at least 90% of the time, then you'd like to apply a 5% boost to their grade (going over 100 is fine). Using the table below, write code that will apply the desired change to the student grades.

Below is code to generate the table + the raw table itself:

#code to generate example dataframe
import pandas as pd
raw_data = {'age': [20, 19, 22, 21, 21, 22, 23, 23], 
        'major': ['Engineering', 'Business', 'Engineering', 'Engineering', 'Business', 'Business', 'Engineering', 'Engineering'], 
        'grade': [88, 95, 92, 70, 68, 92, 75, 85], 
        'perc_attendance': [88,95,95,92,78,87,91,95],        
        'student_id': [1,2,3,4,5,6,7,8]}
df = pd.DataFrame(raw_data, columns = ['student_id', 'age', 'major', 'grade', 'perc_attendance'])
df
student_id age major grade perc_attendance
1 20 Engineering 88 88
2 19 Business 95 95
3 22 Engineering 92 95
4 21 Engineering 70 92
5 21 Business 68 78
6 22 Business 92 87
7 23 Engineering 75 91
8 23 Engineering 85 95

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now