Skip to content

Commit f8cf277

Browse files
committed
Update 570. Managers with at Least 5 Direct Reports.py
1 parent a2a2b2b commit f8cf277

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pandas as pd
2+
3+
def managers_with_five_reports(employee: pd.DataFrame) -> None:
4+
# Count direct reports for each manager
5+
report_counts = employee.groupby('managerId').size().reset_index(name='report_count')
6+
7+
# Identify managerIds with at least five direct reports
8+
valid_managers = report_counts[report_counts['report_count'] >= 5]['managerId']
9+
10+
# Filter the Employee table to get manager names
11+
# Note: Since managerId can be null, we ignore them during merge.
12+
result = employee[employee['id'].isin(valid_managers)][['name']]
13+
14+
# Modify the original DataFrame in place if required.
15+
employee = result
16+
print(result)

0 commit comments

Comments
 (0)