MulaiMulai sekarang secara gratis

Categorizing customers with conditions

Now you'll learn to create conditional expressions. The market research team wants to identify satisfied customers for a follow-up survey - customers with ratings of 4 or higher should be flagged.

The reviews DataFrame is available with 5 rows printed to preview.

Latihan ini adalah bagian dari kursus

Data Transformation with Polars

Lihat Kursus

Petunjuk latihan

  • Check if the "rating" column is greater than or equal to 4.
  • Return "Yes" when the condition is True.
  • Return "No" when the condition is False.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

reviews.with_columns(
  	# Check if rating is 4 or higher
    pl.____(pl.col("rating") >= ____)
  
    # Return "Yes" when True
    .____(pl.____("Yes"))
  
    # Return "No" when False
    .____(pl.____("No"))
    .alias("is_satisfied")
)
Edit dan Jalankan Kode