4. Build a Price List
Difficulty: Easy · Topics: Filtering & Selection
products stores prices in paise: id, name, price_paise and stock.
Return a price list with exactly these columns:
product: the product nameprice: the price in rupees (paise ÷ 100), rounded to 2 decimalsstock_value:price × stock, rounded to 2 decimals
If price_paise or stock is null, the computed values are null.
Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.
Sample data
products
| id | name | price_paise | stock |
|---|---|---|---|
| 1 | Notebook | 4999 | 12 |
| 2 | Pen | 1050 | 100 |
| 3 | Stapler | 25000 | 3 |
Expected output
| product | price | stock_value |
|---|---|---|
| Notebook | 49.99 | 599.88 |
| Pen | 10.5 | 1050 |
| Stapler | 250 | 750 |
Hints
Hint 1
Oneselect can rename a column and compute new ones; name each with .alias().Hint 2
F.round(F.col("price_paise") / 100, 2) converts paise to rupees.Hint 3
Arithmetic with null gives null automatically.Learn the concepts
- select · 4 min read. Choose, rename and compute columns, and why select beats a chain of withColumn calls.
PySpark functions you'll practise
- select
Related problems
- Filter High Earners · Easy · Filtering & Selection
- Distinct User Actions · Easy · Filtering & Selection
- Categorize Orders · Easy · Conditional Logic
- Order Lines with Product Details · Easy · Joins
- Data Quality: Null Count per Column · Medium · Null Handling
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings
Difficulty: Easy · Medium · Hard · PySpark interview roadmap · Learn · All problems