Two files are involved: datasets/csv/employees.csv (one row per employee) and
datasets/csv/departments.csv (one row per department). How much does a
department pay on average?
paths['employees'] and
paths['departments'].department_id.salary per department_name and round the result to two decimals.avg_salary descending, then by department_name ascending.department_name, avg_salary.File questions receive the paths as a third argument:
from pyspark.sql import functions as F
def solve(spark, dfs, paths):
employees = spark.read.csv(paths['employees'], header=True, inferSchema=True)
departments = spark.read.csv(paths['departments'], header=True, inferSchema=True)
# TODO: join, aggregate and sort
return employees
The same data is also preloaded as dfs['employees'] and dfs['departments'] if you
prefer to skip the file reads.
This question runs in your browser - no sign-in needed. Press Run for the sample data and Submit for the hidden data.
These files are loaded into this browser when you run. Their paths are handed to your code as the third argument: solve(spark, dfs, paths). Read one with spark.read.csv(paths['users'], header=True), or skip the read and use dfs['users'].
employees]departments]Column names and order must match. Sort order is specified in the question.