Top earner per department

ranking

Top 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 NameType
employee_idint64
namestr
departmentstr
salaryint64
manager_idfloat64
hire_datestr

employeesExample Input

employee_idnamedepartmentsalarymanager_idhire_date
1Ravi KumarExecutive240000NULL2018-01-15
2Mei LinEngineering18500012018-06-04
3Sofia RossiEngineering14200022019-02-18
4James ParkEngineering12800022019-09-02
5Aisha BelloEngineering11900032020-04-27
6Tom FischerEngineering9800032021-11-08
7Diego AlvarezAnalytics16800012018-10-22
8Hannah WeberAnalytics13400072020-01-13

Example Output

departmentnamesalary
AnalyticsDiego Alvarez168000
EngineeringMei Lin185000
ExecutiveRavi Kumar240000

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.