BaşlayınÜcretsiz Başlayın

Chaining multiple conditions

You can also chain multiple conditions together. The product team wants to categorize products as "Large", "Medium", or "Small" based on their size for shipping optimization.

Bu egzersiz

Data Transformation with Polars

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Check if the "size" column equals "100ml" and return "Large".
  • Check if the "size" column equals "50ml" and return "Medium".
  • Return "Small" for all other sizes and name the column "size_category".

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

reviews.with_columns(
  	# Check if size is "100ml" and return "Large"
    pl.when(pl.col("____") == "____").then(pl.lit("____"))
  
    # Check if size is "50ml" and return "Medium"
    .____(pl.col("size") == "____").then(pl.lit("____"))
  
    # Return "Small" for other sizes
    .____(pl.lit("____"))
    .alias("size_category")
)
Kodu Düzenle ve Çalıştır