코딩 테스트/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

'코딩 테스트 > Pandas' 카테고리의 다른 글

Students and Examinations  (0) 2024.12.22
Average Time of Process per Machine  (0) 2024.12.21
Rising Temperature  (0) 2024.12.21
Customer Who Visited but Did Not Make Any Transcations  (1) 2024.12.20
Product Sales Analysis 1  (0) 2024.12.20