0
点赞
收藏
分享

微信扫一扫

pandas基础用法——数据校验

九点韶留学 2022-04-13 阅读 79
python

(笔记:python数据分析学不会?,看大佬如何用pandas玩转数据分析!_哔哩哔哩_bilibili)

pandas数据校验

import pandas as pd


# 用assert校验
def ScoreValidation(row):
    try:
        assert 0 <= row.Score <= 100
    except:
        print(f"#{row.ID}\tstudent {row.Name} has an invalid score {row.Score}!")


# 用条件语句校验
def ScoreValidation2(row):
    if not 0 <= row.Score <= 100:
        print(f"#{row.ID}\tstudent {row.Name} has an invalid score {row.Score}!")


df = pd.read_excel("./1.xlsx")
df.apply(ScoreValidation, axis=1)
# df.apply(ScoreValidation2, axis=1)
# 注:axis=0表示从上到下,此处数据校验是一行一行(从左到右),因此设置axis=1
举报

相关推荐

0 条评论