Skip to content

8. Categorize Orders

Difficulty: Easy · Topics: Conditional Logic, Filtering & Selection

Classify every row of orders into a tier:

Return order_id and tier.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

orders

order_idcustomeramount
1Asha1500
2Ben500
3Chitra499
4Dev1000
5Eshanull

Expected output

order_idtier
1High
2Medium
3Low
4High
5Low

Hints

Hint 1F.when(cond, value).when(cond2, value2).otherwise(default) works like a CASE expression.
Hint 2Order matters: conditions are checked top to bottom.
Hint 3A null amount makes every condition null, so it falls through to otherwise.

Learn the concepts

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance

Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice