Koşullu Beklentiler

Great Expectations ile Veri Kalitesine Giriş

Davina Moossazadeh

Data Scientist

Koşullu Beklentiler nedir?

Koşullu Beklentiler - Verinin bir alt kümesi için Beklentiler

Neden? Çünkü bazı değişkenler diğerlerinin değerlerine bağlıdır

Örnek:

  • review_count değeri 0 olan tüm satırlarda star_rating sütununun 0 olmasını bekleyen bir Beklenti
1 https://docs.greatexpectations.io/docs/core/customize_expectations/expectation_conditions/
Great Expectations ile Veri Kalitesine Giriş

Koşullu Beklentiler için sözdizimi

Varlık Beklentileri iki ek argümanla Koşullu Beklentilere dönüştürülebilir:

  1. row_condition
    • Koşullu Beklentinin uygulanacağı veri alt kümesini tanımlayan boole ifade dizesi
  2. condition_parser
    • row_condition sözdizimini tanımlayan dize
Great Expectations ile Veri Kalitesine Giriş

Koşul ayrıştırıcı

Koşullu Beklentileri pandas ile kullanırken bu argüman "pandas" olarak ayarlanmalıdır

expectation = gx.Expect...(
    **kwargs,
    condition_parser="pandas",
    row_condition=...
)
Great Expectations ile Veri Kalitesine Giriş

Satır koşulu

pandas Sözdizimi
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")
Great Expectations 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")'
Great Expectations ile Veri Kalitesine Giriş

Satır koşulu

Kurallar
  1. İçeride tek tırnak kullanmayın

    • row_condition="foo=='Two Two'"
    • row_condition='foo=="Two Two"' İkinci madde noktasındaki `row_condition` sözdiziminin doğru olduğunu belirten onay işareti.
  2. İçeride satır sonu kullanmayın

    • row_condition="""
      foo=="Two Two"
      """  
      
    • row_condition='foo=="Two Two"' İkinci madde noktasındaki `row_condition` sözdiziminin doğru olduğunu belirten onay işareti.
Great Expectations ile Veri Kalitesine Giriş

Örnek Beklenti: yıldız puanı

Koşul yok
expectation = gx.expectations.\
ExpectColumnValuesToBeBetween(
    column="price_usd",
    max_value=10,
)
validation_results = batch.validate(
    expect=expectation
)
print(validation_results.success)
False
Koşullu
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
Great Expectations ile Veri Kalitesine Giriş

Hadi pratik yapalım!

Great Expectations ile Veri Kalitesine Giriş

Preparing Video For Download...