Mode: On-Campus Exam Pattern: 1 DSA + 1 Python Data Science - 60mins OA Date: 2026-10-15
Language: Python 3 · Library: pandas · Function:
topEmp(df)
Given data of employee sales across different sales branches as a pandas dataframe, find the employee who has the highest total sales across all branches.
0.The dataframe consists of three columns:
| Column | Description |
|---|
emp_id | Employee ID |
branch_code | Unique identifier for each branch |
sales | Sales amounts |
Consider the following dataframe:
| emp_id | branch_code | sales |
|---|---|---|
| 1 | b01 | 100 |
| 1 | b01 | 200 |
| 1 | b02 | 50 |
| 2 | b01 | 150 |
| 2 | b02 | 10 |
| 2 | b02 | 20 |
The dataframe after performing the steps is:
| emp_id |
|---|
| 1 |
Complete the function topEmp in the editor below.
topEmp has the following parameter(s):
df: a pandas dataframepandas dataframe: the results of processingdf ≤ 1000A CSV file that describes the dataframe.
emp_id,branch_code,sales
1,b01,113
1,b01,126
1,b02,108
2,b01,178
emp_id
1
Employee 1 has total sales of 239 in branch b01 and 108 in b02 whereas employee 2 has sales of 178 and no sales in branch b02.
emp_id,branch_code,sales
1,b01,193
1,b02,151
1,b02,195
2,b01,114
2,b01,122
2,b01,128
2,b02,103
2,b02,142
emp_id
Employee 1 has total sales of 193 in b01 and 346 in b02. Employee 2 has total sales ...
The rest of this explanation was cut off in the original screenshot.
#!/usr/bin/python3
# Complete the 'topEmp' function below.
#
# The function is expected to return a pandas dataframe.
#
def topEmp(df):
# Write your code here
Microsoft • 149 views
Microsoft • 637 views
Microsoft • 434 views
Microsoft • 205 views
Microsoft • 219 views