Nhập môn Data Quality với Great Expectations
Davina Moossazadeh
Data Scientist
Kỳ vọng có điều kiện - Áp dụng cho một tập con dữ liệu
Vì sao? Vì một số biến phụ thuộc vào giá trị của biến khác
Ví dụ:
star_rating phải bằng 0 cho mọi hàng có review_count bằng 0Dataset Expectation có thể chuyển thành Kỳ vọng có điều kiện với hai tham số bổ sung:
row_conditioncondition_parserrow_conditionKhi dùng pandas cho Kỳ vọng có điều kiện, đặt tham số này là "pandas"
expectation = gx.Expect...(
**kwargs,
condition_parser="pandas",
row_condition=...
)
df["foo"] == 'Two Two'
df["foo"].notNull()
df["foo"] <= datetime.date(2023, 3, 13)
(df["foo"] < 5) & (df["foo"] >= 3.14)
df["foo"].str.startswith("bar")
row_condition'foo == "Two Two"'
'foo.notNull()'
'foo <= datetime.date(2023, 3, 13)'
'(foo > 5) & (foo <= 3.14)'
'foo > 5 and foo <= 3.14'
'foo.str.startswith("bar")'
Không dùng dấu nháy đơn bên trong
row_condition="foo=='Two Two'" row_condition='foo=="Two Two"' 
Không xuống dòng bên trong
row_condition="""
foo=="Two Two"
"""
row_condition='foo=="Two Two"' 
expectation = gx.expectations.\
ExpectColumnValuesToBeBetween(
column="price_usd",
max_value=10,
)
validation_results = batch.validate(
expect=expectation
)
print(validation_results.success)
False
expectation = gx.expectations.\
ExpectColumnValuesToBeBetween(
column="price_usd",
max_value=10,
condition_parser='pandas',
row_condition='mark_price_usd < 10',
)
validation_results = batch.validate(
expect=expectation
)
print(validation_results.success)
True
Nhập môn Data Quality với Great Expectations