Get startedGet started for free

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.

This exercise is part of the course

Data Transformation with Polars

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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 and Run Code