코딩 테스트/Pandas

Employee Bonus

susinlee 2024. 12. 22. 13:16

[문제]

https://leetcode.com/problems/employee-bonus/description/

 

 

[풀이]

 

Pandas

import pandas as pd

def employee_bonus(employee: pd.DataFrame, bonus: pd.DataFrame) -> pd.DataFrame:
    merged = pd.merge(employee, bonus, on='empId', how='left')
    cond1 = merged['bonus'].isna()
    cond2 = merged['bonus'] < 1000
    return merged[cond1 | cond2][['name', 'bonus']]

 

SQL

select name,
       bonus
from Employee e
left join Bonus b
    ON e.empId = b.empId
where ifnull(bonus, 0) < 1000