A retail company wants to list prices containing an added 15% VAT tax for all electronic products. You need to calculate the final price and filter to list only Electronics.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| product_id | product_name | category | price |
|---|---|---|---|
| 201 | Laptop | Electronics | 1000.0 |
| 202 | Desk Chair | Furniture | 150.0 |
| 203 | Headphones | Electronics | 120.0 |
| 204 | Coffee Maker | Appliances | 80.0 |
| 205 | Smart Watch | Electronics | 250.0 |
product_id,product_name,category,price 201,Laptop,Electronics,1000.0 202,Desk Chair,Furniture,150.0 203,Headphones,Electronics,120.0 204,Coffee Maker,Appliances,80.0 205,Smart Watch,Electronics,250.0
Copy this starter template to write the data transformation logic:
# starter.py - Product Price Analysis
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
def analyze_products():
spark = SparkSession.builder.appName("ProductAnalysis").getOrCreate()
# TODO: Read dataset.csv, add VAT tax column, filter Electronics
pass
if __name__ == "__main__":
analyze_products()price_with_vat by applying df.withColumn() and multiplying the price column by 1.15.
col("category") == "Electronics".