Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,31 @@ FROM
USING (id);
```

### **Pandas**

```python
import pandas as pd


def find_managers(employee: pd.DataFrame) -> pd.DataFrame:
# Group the employees by managerId and count the number of direct reports
manager_report_count = (
employee.groupby("managerId").size().reset_index(name="directReports")
)

# Filter managers with at least five direct reports
result = manager_report_count[manager_report_count["directReports"] >= 5]

# Merge with the Employee table to get the names of these managers
result = result.merge(
employee[["id", "name"]], left_on="managerId", right_on="id", how="inner"
)

# Select only the 'name' column and drop the 'id' and 'directReports' columns
result = result[["name"]]

return result

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,31 @@ FROM
USING (id);
```

### **Pandas**

```python
import pandas as pd


def find_managers(employee: pd.DataFrame) -> pd.DataFrame:
# Group the employees by managerId and count the number of direct reports
manager_report_count = (
employee.groupby("managerId").size().reset_index(name="directReports")
)

# Filter managers with at least five direct reports
result = manager_report_count[manager_report_count["directReports"] >= 5]

# Merge with the Employee table to get the names of these managers
result = result.merge(
employee[["id", "name"]], left_on="managerId", right_on="id", how="inner"
)

# Select only the 'name' column and drop the 'id' and 'directReports' columns
result = result[["name"]]

return result

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pandas as pd


def find_managers(employee: pd.DataFrame) -> pd.DataFrame:
# Group the employees by managerId and count the number of direct reports
manager_report_count = (
employee.groupby("managerId").size().reset_index(name="directReports")
)

# Filter managers with at least five direct reports
result = manager_report_count[manager_report_count["directReports"] >= 5]

# Merge with the Employee table to get the names of these managers
result = result.merge(
employee[["id", "name"]], left_on="managerId", right_on="id", how="inner"
)

# Select only the 'name' column and drop the 'id' and 'directReports' columns
result = result[["name"]]

return result