Skip to content

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

idnamedepartmentsalary
1AshaEngineering72000
2BenSales48000
3ChitraEngineering95000
4DevHR51000
5EshaSales50000

Expected output

namesalary
Chitra95000
Asha72000
Dev51000

Hints

Hint 1Use .filter() with a Column condition such as F.col("salary") > 50000.
Hint 2Employees with a null salary must not appear — comparisons with null are never true.
Hint 3Sort descending with F.col("salary").desc().

Learn the concepts

PySpark functions you'll practise

Related problems

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