[문제]

https://leetcode.com/problems/project-employees-i/description/

 

 

[풀이]

1. project 테이블을 기준으로 left join 을 해준다.

2. project_id 별로 experience_years의 평균을 구해주는데 소수점 둘째 자리까지 반올림 해준다.

3. 컬럼명을 average_years 로 변경해준다.

 

Pandas

import pandas as pd

def project_employees_i(project: pd.DataFrame, employee: pd.DataFrame) -> pd.DataFrame:
    
    return project.merge(employee, how='left').groupby('project_id')['experience_years'].mean().round(2).reset_index(name='average_years')

 

SQL

# Write your MySQL query statement below
SELECT p.project_id
       , ROUND(AVG(experience_years), 2) AS average_years
FROM Project p
LEFT JOIN Employee e
    ON p.employee_id = e.employee_id
GROUP BY p.project_id

'코드카타 > Pandas' 카테고리의 다른 글

Queries Quality and Percentage  (1) 2024.12.27
Percentage of Users Attended a Contest  (0) 2024.12.26
Average Selling Price  (0) 2024.12.25
Not Boring Movies  (0) 2024.12.25
Confirmation Rate  (0) 2024.12.24

+ Recent posts