SIMPLEST PANDAS  SOLUTION WITH EXPLANTION ❤
IntuitionApproach

Merge DataFrames: Combine the employee and department DataFrames using departmentId (from employee) and id (from department) to include depar
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->Here’s a explanation of the code:

1. Merge DataFrames: Combine the employee and department DataFrames using departmentId (from employee) and id (from department) to include department names.
merged = employee.merge(department, left_on='departmentId', right_on='id')

2. Group and Transform: Use groupby on department names to find the maximum salary in each department and assign it to all rows in the group.
merged['max_salary'] = merged.groupby('name_y')['salary'].transform(max)

3. Filter Rows: Keep only the rows where the employee's salary matches the maximum salary in their department.

result = merged[merged['salary'] == merged['max_salary']]


![please-upvote-please.jpg](https://assets.leetcode.com/users/images/7380575a-6e98-440a-9472-4526eb3ba087_1736871036.8309698.jpeg)




# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->68.18 MB✔
Beats 84.97%✔

# Code
```pythondata []
import pandas as pd

def department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame:
    merged = employee.merge(department , left_on = 'departmentId' , right_on = 'id')
    rt = merged[merged['salary'] == merged.groupby('name_y')['salary'].transform(max)]
    rt = rt[['name_y' , 'name_x' , 'salary']].rename(columns = {'name_y' : 'Department' , 'name_x': 'Employee' , 'salary' : 'Salary'})
    return rt
```
['Pandas']