Salary Share by Department

Medium
Aggregation
Arithmetic

Salary Share by Department

The employees table contains salaries by department.

Return department, payroll, payroll_share, where payroll is the department's total salary and payroll_share is that department's percentage of total company payroll, rounded to 2 decimal places. Sort by department ascending.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input data

1 DataFrame

These DataFrames are passed to solve(spark, dfs). Access one with dfs['name'].

df.employees7 rows
employee_id (int)department (string)salary (double)
1Engineering100000
2Engineering80000
3Sales60000
4Sales50000
5HR40000
6Marketing70000
7Engineering120000

Return these columns

department(string)
payroll(double)
payroll_share(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.