File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
LeetCode SQL 50 Solution/570. Managers with at Least 5 Direct Reports Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments