
Top earner per department
mediumTop earner per department
Salesforce Pandas Interview Question
Salesforce's HR team is reviewing pay and wants the highest-paid person in every department.
Using the employees DataFrame, return each department with the name and salary of its highest-paid employee. Sort the rows by department. Assign the answer to result.
Asked of
- Data Analyst
- Product Analyst
- Business Analyst
- Analytics Engineer
- Data Scientist
employeesDataFrame16 rows
| Column Name | Type |
|---|---|
| employee_id | int64 |
| name | str |
| department | str |
| salary | int64 |
| manager_id | float64 |
| hire_date | str |
employeesExample Input
| employee_id | name | department | salary | manager_id | hire_date |
|---|---|---|---|---|---|
| 1 | Ravi Kumar | Executive | 240000 | NULL | 2018-01-15 |
| 2 | Mei Lin | Engineering | 185000 | 1 | 2018-06-04 |
| 3 | Sofia Rossi | Engineering | 142000 | 2 | 2019-02-18 |
| 4 | James Park | Engineering | 128000 | 2 | 2019-09-02 |
| 5 | Aisha Bello | Engineering | 119000 | 3 | 2020-04-27 |
| 6 | Tom Fischer | Engineering | 98000 | 3 | 2021-11-08 |
| 7 | Diego Alvarez | Analytics | 168000 | 1 | 2018-10-22 |
| 8 | Hannah Weber | Analytics | 134000 | 7 | 2020-01-13 |
Example Output
| department | name | salary |
|---|---|---|
| Analytics | Diego Alvarez | 168000 |
| Engineering | Mei Lin | 185000 |
| Executive | Ravi Kumar | 240000 |
Explanation
In the example, Mei Lin earns 185,000, the most in Engineering, so she is the Engineering row even though Sofia Rossi and James Park work in the same department.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
Salesforce
Difficulty
medium
Topic
ranking
Language
Pandas
Your code
Loading Python in the background. You can start writing.