import pandas as pd def score_valication(row): try: assert 0 <= row.Score <= 100 except: print(f'#{row.ID} student {row.Name} has an invalid score {row.Score}') students = pd.read_excel('C:/Temp/Students.xlsx') # print(students) students.apply(score_valication, axis=1)