How do we construct multi-tier customer spend segmentation rules with chained when/otherwise logic?
Chaining multiple when() statements sequentially to implement complex CASE-WHEN logic in PySpark.
Multi-tier loyalty programs, pricing bracket allocations, and credit risk tiering.
from pyspark.sql.functions import col, when
df = df.withColumn(
"customer_segment",
when(col("spend") > 10000, "High Value")
.when(col("spend") >= 2500, "Mid Tier")
.otherwise("Standard")
)Practice typing production-grade PySpark code for Chained Multi-Branch Conditional Classification.