The marketing department wants to categorize customers into age demographics for tailored marketing campaigns. Classify users under 30 as 'Young', 30-50 as 'Adult', and others as 'Senior'.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| customer_id | name | age |
|---|---|---|
| 1 | Alice | 25 |
| 2 | Bob | 45 |
| 3 | Charlie | 60 |
| 4 | David | 30 |
| 5 | Eve | 22 |
customer_id,name,age 1,Alice,25 2,Bob,45 3,Charlie,60 4,David,30 5,Eve,22
Copy this starter template to write the data transformation logic:
# starter.py - Customer Age Categories
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, when
def categorize_customers():
spark = SparkSession.builder.appName("AgeCategories").getOrCreate()
# TODO: Read dataset.csv, apply conditional when statements
pass
if __name__ == "__main__":
categorize_customers()age_group.
when(condition, value) to map matching values. Chain further conditional matches with additional .when() calls, and finalize using .otherwise() to handle default cases.