The operations team needs a clean report displaying employee names paired with their department titles. You must join the employee profiles table with the department metadata table.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| employee_id | name | dept_id |
|---|---|---|
| 1 | Alice | 10 |
| 2 | Bob | 20 |
| 3 | Charlie | 10 |
| 4 | David | 30 |
| 5 | Eve | 20 |
| --- | ||
| dept_id | dept_name | |
| 10 | Engineering | |
| 20 | Marketing | |
| 30 | Sales |
employee_id,name,dept_id 1,Alice,10 2,Bob,20 3,Charlie,10 4,David,30 5,Eve,20 --- dept_id,dept_name 10,Engineering 20,Marketing 30,Sales
Copy this starter template to write the data transformation logic:
# starter.py - Basic DataFrame Joins
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
def join_data():
spark = SparkSession.builder.appName("JoinLab").getOrCreate()
# Raw Mock Data
emp_data = [(1, "Alice", 10), (2, "Bob", 20), (3, "Charlie", 10), (4, "David", 30), (5, "Eve", 20)]
dept_data = [(10, "Engineering"), (20, "Marketing"), (30, "Sales")]
# TODO: Create DataFrames, join on dept_id, print name and dept_name
pass
if __name__ == "__main__":
join_data()join() method on emp_df. Pass the second DataFrame (dept_df), the join column key on="dept_id", and the join type how="inner" as arguments.
name and dept_name columns.
show() method.