使用 pandas_schema 验证空列

问题描述 投票:0回答:1

我正在使用 python 3.7 和 Pandas_schema 尝试为任何空的 CSV 列生成验证警告。我能够成功运行代码,但没有返回任何警告。

这是我目前所拥有的:

from io import StringIO
from pandas_schema import Column, Schema
from pandas_schema.validation_warning import ValidationWarning

schema = Schema([
    Column('Test_Column1', allow_empty=False),
    Column('Test_Column2', allow_empty=False),

])

test_data = pd.read_csv(StringIO('''Test_Column1,Test_Column2
test_data1, ''')) # Showing empty column for Test_Column2

errors = schema.validate(test_data)

for error in errors:
    print(error)

有人能帮我指出正确的方向吗?

python-3.x pandas dataframe validation schema
1个回答
0
投票

文档说:

allow_empty – 如果空列被认为有效则为真。如果我们错了 将该逻辑留给验证

所以我猜如果你将 allow_empty 设置为 False,验证器——你没有作为参数传递——确定它是被验证为真还是假。由于没有验证器,因此没有验证错误

https://multimeric.github.io/PandasSchema/

© www.soinside.com 2019 - 2024. All rights reserved.