017_数据效验_轴的概念

 

 

import pandas as pd

# 校验函数 : 校验数据; 校验数据关系
# 校验结果 : run; excel
def score_validation(row):
    # 方法一
    try:
        assert 0 <= row.Score <= 100
    except:
        print(f"#{row.ID}\t\tstudent{row.Name} has an invalid score {row.Score}")

    # 方法二
    # if not 0 <= row.Score <= 100:
    #     print(f"#{row.ID}\t\tstudent{row.Name} has an invalid score {row.Score}")


if __name__ == '__main__':
    students = pd.read_excel("C:/Users/18124/Desktop/pandas/017_数据效验_轴的概念/Students.xlsx")
    print(students)

    # 校验数据 : 按行校验
    students.apply(score_validation, axis=1)  # axis=0 : 从上到下;  axis=1 : 从左到右;

 

posted @ 2021-02-17 20:39  火焰马  阅读(62)  评论(0编辑  收藏  举报