Skip to content

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:

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

idnameprice_paisestock
1Notebook499912
2Pen1050100
3Stapler250003

Expected output

productpricestock_value
Notebook49.99599.88
Pen10.51050
Stapler250750

Hints

Hint 1One select can rename a column and compute new ones; name each with .alias().
Hint 2F.round(F.col("price_paise") / 100, 2) converts paise to rupees.
Hint 3Arithmetic with null gives null automatically.

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

Difficulty: Easy · Medium · Hard · PySpark interview roadmap · Learn · All problems