The finance team is planning new budgets. They need a summary report containing the total salary spend and the average salary per department.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| employee_id | name | department | salary |
|---|---|---|---|
| 1 | Alice | Engineering | 120000 |
| 2 | Bob | Engineering | 100000 |
| 3 | Charlie | Marketing | 90000 |
| 4 | David | Sales | 85000 |
| 5 | Eve | Marketing | 95000 |
employee_id,name,department,salary 1,Alice,Engineering,120000 2,Bob,Engineering,100000 3,Charlie,Marketing,90000 4,David,Sales,85000 5,Eve,Marketing,95000
Copy this starter template to write the data transformation logic:
# starter.py - Department Salary Report
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, avg, sum
def generate_report():
spark = SparkSession.builder.appName("DeptReport").getOrCreate()
# TODO: Read dataset.csv, group by department, aggregate sum and avg
pass
if __name__ == "__main__":
generate_report()groupBy("department") to group rows sharing the same department value.
.agg() method combining sum("salary") and avg("salary"). Use .alias() to rename the output columns for cleaner reports.