import pandas as pd
df = pd.read_csv (r'result_withoutTotal.csv', index_col=0)
df['Total'] = (((5/100)*(df['Ass1']+df['Ass3']))+((15/100)*(df['Ass2']+df['Ass4']))+((60/100)*df['Exam']))
df.loc[df['Total'] > 100, 'Total'] = 100 #
df['Final'] = round(df['Total']) #rounds up the Total to the nearest integer and saves it in column Final
print(df)
for index, row in df.iterrows():
if row['Total'] >= 50 and row['Exam'] >= 48:
print('Student ID:', str(index) + ' Passed')
elif row['Exam'] < 48 and row['Final'] > 44:
print('Student ID:', str(index) + ' Failed and Will have 44')
print('')
print(df)
The Question
- If a student failed the hurdle (Exam >= 48), the max Final is 44. No change to Final score if Final <44.
So in the For loop ( ELIF ) part i need to change any value in column 'Final' to 44 if the conditional statement is true in the main dataframe(df), I just cant figure it out, i tried row['Final] = 44 but that just changes it within the for loop.