The finance team needs a compensation report. Calculate a standard 10% bonus for each employee earning less than $100,000, and rename the output column to annual_bonus.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| employee_id | name | salary |
|---|---|---|
| 1 | Alice | 120000 |
| 2 | Bob | 85000 |
| 3 | Charlie | 95000 |
| 4 | David | 110000 |
| 5 | Eve | 70000 |
employee_id,name,salary 1,Alice,120000 2,Bob,85000 3,Charlie,95000 4,David,110000 5,Eve,70000
Copy this starter template to write the data transformation logic:
# starter.py - Employee Bonus Calculator
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, when
def calculate_bonuses():
spark = SparkSession.builder.appName("BonusCalculator").getOrCreate()
# TODO: Read dataset.csv, map bonuses with when conditions, rename output
pass
if __name__ == "__main__":
calculate_bonuses()annual_bonus using withColumn().
withColumn(), evaluate the condition col("salary") < 100000. If met, calculate col("salary") * 0.1, otherwise return 0.