[문제]
https://leetcode.com/problems/classes-more-than-5-students/
[풀이]
1. class로 그룹화 해준 뒤 student의 수를 세어준다
2. student 수가 5이상 행들만 필터링하고 class열만 출력한다
Pandas
import pandas as pd
def find_classes(courses: pd.DataFrame) -> pd.DataFrame:
df = courses.groupby('class')['student'].count().reset_index(name='cnt')
return df[df['cnt'] >= 5][['class']]
SQL
SELECT class
FROM Courses
GROUP BY class
HAVING COUNT(student) >= 5
'코딩 테스트 > Pandas' 카테고리의 다른 글
103. Find Followers Count (0) | 2025.01.08 |
---|---|
101. Product Sales Analysis III (0) | 2025.01.06 |
100. User Activity for the Past 30 Days I (0) | 2025.01.05 |
Game Play Analysis IV (0) | 2025.01.01 |
Immediate Food Delivery II (0) | 2024.12.31 |