分批讀取資料

Great Expectations 資料品質入門

Davina Moossazadeh

Data Scientist

Kaggle 氣象資料

一個包含 Kaggle 氣象資料的 pandas DataFrame,欄位有:「Location」、「Date_Time」、「Temperature_C」、「Humidity_pct」、「Precipitation_mm」、「Wind_Speed_kmh」。DataFrame 共有 87,118 列。

Great Expectations 資料品質入門

批次定義

批次定義(Batch Definition)-設定如何將資料資產切分以供測試

batch_definition = data_asset.add_batch_definition_whole_dataframe(

name="my_batch_definition" )
print(batch_definition)
id='69e2a81d-1c28-4d1a-b66e-52cdc1198266' 
name='my_batch_definition' 
partitioner=None
1 https://docs.greatexpectations.io/docs/core/connect_to_data/dataframes/
Great Expectations 資料品質入門

批次

批次(Batch)-可用來執行驗證的一組紀錄

batch = batch_definition.get_batch(

batch_parameters={"dataframe": dataframe} )
Great Expectations 資料品質入門

批次

data_source_other.jpg

data_source_pandas.jpg

Great Expectations 資料品質入門

Batch 物件

可以像在 pandas 中使用 .head()

print(batch.head())

Screenshot 2024-07-16 at 11.49.00.png

1 表格改編自 https://www.kaggle.com/datasets/prasad22/weather-data
Great Expectations 資料品質入門

Batch 物件

print(batch.head(fetch_all=True))

Screenshot 2024-07-22 at 14.02.00.png

Great Expectations 資料品質入門

Batch 物件

.columns() 顯示所有 DataFrame 欄位(注意有 ()

print(batch.columns())
['Location',
 'Date_Time',
 'Temperature_C',
 'Humidity_pct',
 'Precipitation_mm',
 'Wind_Speed_kmh']
Great Expectations 資料品質入門

速查表

從資料資產建立批次定義:

batch_definition = data_asset. \
add_batch_definition_whole_dataframe(
  name: str
)

從批次定義建立批次:

batch = batch_definition.get_batch(
  batch_parameters={"dataframe": dataframe}
)

取得 Batch DataFrame 的列:

batch.head(fetch_all: bool)  

取得 Batch DataFrame 的欄位清單:

batch.columns()
Great Expectations 資料品質入門

一起來練習吧!

Great Expectations 資料品質入門

Preparing Video For Download...