开始使用免费开始使用

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.

本练习是课程的一部分

Data Transformation with Polars

查看课程

练习说明

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

交互式实操练习

通过完成这段示例代码来试试这个练习。

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")
)
编辑并运行代码