การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น
Davina Moossazadeh
Data Scientist
Expectation - ข้อความยืนยันเกี่ยวกับข้อมูลที่ตรวจสอบได้
Expectation - ข้อความยืนยันเกี่ยวกับข้อมูลที่ตรวจสอบได้
![DataFrame ของ pandas ที่มีข้อมูลการผลิตพลังงานหมุนเวียน ประกอบด้วยคอลัมน์: "Time", "Energy delta[Wh]", "GHI", "temp", "pressure", "humidity", "wind_speed", "rain_1h", "snow_1h" และ "clouds_all" โดย DataFrame มีทั้งหมด 118,066 แถว](https://assets.datacamp.com/production/repositories/6700/datasets/3001d0e616168c043e1340b2981ec3d363dcd971/Screenshot%202024-07-22%20at%2014.16.18.png)
gx.expectations.Expect...(...)
คลาส GX (Expectations): PascalCase
ฟังก์ชัน / เมทอด GX: snake_case
row_count_expectation = gx.expectations.ExpectTableRowCountToEqual(value=118000 )validation_results = batch.validate(expect=row_count_expectation )
print(validation_results)
{
"success": false,
"expectation_config": {
"type": "expect_table_row_count_to_equal",
"kwargs": {"batch_id": "my_pandas_datasource-my_dataframe_asset", "value": 118000},
"meta": {},
"rendered_content": [{"name": "atomic.prescriptive.summary", "value": {"schema": {"type": "com.superconductive.rendered.string"}, "template": "Must have exactly $value rows.", "params": {"value": {"schema": {"type": "number"}, "value": 118000}}}, "value_type": "StringValueType"}]
},
"result": {"observed_value": 118066},
"meta": {},
"exception_info": {"raised_exception": false, "exception_traceback": null, "exception_message": null},
"rendered_content": [{"name": "atomic.diagnostic.observed_value", "value": {"schema": {"type": "com.superconductive.rendered.string"}, "template": "118066", "params": {}}, "value_type": "StringValueType"}]
}
print(validation_results.describe())
{
"expectation_type": "expect_table_row_count_to_equal",
"success": false,
"kwargs": {
"batch_id": "my_pandas_datasource-my_dataframe_asset",
"value": 118000
},
"result": {
"observed_value": 118066
}
}
print(validation_results.success)
False
print(validation_results["success"])
False
print(validation_results.result)
{'observed_value': 118066}
print(validation_results["result"])
{'observed_value': 118066}
Shape Expectations:
ExpectTableRowCountToEqual(value: int)
ExpectTableRowCountToBeBetween(
min_value: int, max_value: int
)
ExpectTableColumnCountToEqual(
value: int
)
ExpectTableColumnCountToBeBetween(
min_value: int, max_value: int
)
Column name Expectations:
ExpectTableColumnsToMatchSet(
column_set: set
)
ExpectColumnToExist(column: str)
สร้าง Expectation:
gx.expectations.Expect...(...)
ตรวจสอบ Expectation:
validation_results = batch.validate(
expect=expectation
)
สร้าง Expectation สำหรับจำนวนแถว:
expectation = gx.expectations. \
ExpectTableRowCountToEqual(
value: int
)
ตรวจสอบผลการ Validation:
validation_results.describe()
validation_results.success
validation_results.result
การตรวจสอบคุณภาพข้อมูลด้วย Great Expectations เบื้องต้น