import pandas as pd
def score_validation(row):
try:
assert 0<=row.Score<=100
except:
print(f'Idx: {row.idx} StudentName: {row.Name} has an invalid score: {row.Score}')
# 索引列:学员Id,数据列:学员姓名,学员成绩
studentsScores = pd.read_excel('D:/studentsScores.xlsx')
# 使用pandas 校验分数
# 逐行校验数据, axis=1 按照行进行(数据是每行从左向右)
# 逐行校验数据, axis=0 按照列进行(数据是每列从上到下)
studentsScores.apply(score_validation, axis=1)
print(studentsScores)
视频地址:https://www.bilibili.com/video/av88814463?p=17
来源:oschina
链接:https://my.oschina.net/ski/blog/3179566