1. Filter High Earners
Difficulty: Easy · Topics: Filtering & Selection
The employees DataFrame lists everyone in the company. salary may be null for some employees.
Return the name and salary of every employee who earns strictly more than 50,000, sorted by salary from highest to lowest.
Row order matters for this problem. Your code is graded on 3 test cases, including hidden edge cases.
Sample data
employees
| id | name | department | salary |
|---|---|---|---|
| 1 | Asha | Engineering | 72000 |
| 2 | Ben | Sales | 48000 |
| 3 | Chitra | Engineering | 95000 |
| 4 | Dev | HR | 51000 |
| 5 | Esha | Sales | 50000 |
Expected output
| name | salary |
|---|---|
| Chitra | 95000 |
| Asha | 72000 |
| Dev | 51000 |
Hints
Hint 1
Use.filter() with a Column condition such as F.col("salary") > 50000.Hint 2
Employees with anull salary must not appear — comparisons with null are never true.Hint 3
Sort descending withF.col("salary").desc().Learn the concepts
- select · 6 min read. Choose, rename and compute columns, and why select beats a chain of withColumn calls.
- filter / where · 5 min read. Keep the rows that match a condition, and the null and operator traps that silently drop data.
- orderBy · 4 min read. Sort rows ascending or descending, control where nulls go, and know what a global sort costs.
PySpark functions you'll practise
- filter
- select
- orderBy
Related problems
- Distinct User Actions · Easy · Filtering & Selection
- Build a Price List · Easy · Filtering & Selection
- Paid Orders in March · Easy · Filtering & Selection
- Sort Delivery Options · Easy · Filtering & Selection
- Add a Bonus Column · Easy · Filtering & Selection
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice