Managers with at least five direct reports
employee(id, name, department, managerId), where managerId references another employee's id. Return the names of managers who have at least five direct reports.
import pandas as pd
def big_managers(employee: pd.DataFrame) -> pd.DataFrame:
# your code here
Write the implementation.
Count how many employees report to each manager, then keep managers meeting the threshold and look up their names. Group by managerId with size(), take the index where the count is >= 5, and return the names of employees whose id is in that set.
- ✗Counting department size instead of reports per managerId
- ✗Counting employee id occurrences instead of grouping reports
- ✗Equating top-of-hierarchy with having five reports
- →Why group by managerId rather than by department?
- →How would you also report the report count per manager?
Count reports per manager, threshold the count, then map the qualifying ids back to names.
import pandas as pd
def big_managers(employee: pd.DataFrame) -> pd.DataFrame:
counts = employee.groupby('managerId').size()
mgr_ids = counts[counts >= 5].index
return employee[employee['id'].isin(mgr_ids)][['name']]
groupby('managerId').size() counts how many employees report to each manager; filtering to >= 5 gives the manager ids of interest, and isin on id recovers their names. Grouping by department or counting id occurrences would not measure direct reports.