Table: Customer
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| referee_id | int |
+-------------+---------+
SQL에서 id는 이 테이블의 기본 키 열입니다.
이 테이블의 각 행은 고객의 id, 이름, 그리고 그들을 추천한 고객의 id를 나타냅니다.
문제
고객 id = 2가 추천하지 않은 고객들의 이름을 찾아주세요.
결과 테이블은 순서에 관계없이 반환해주세요.
결과 형식은 아래 예시와 같습니다.
Example 1:
Input:
Customer table:
+----+------+------------+
| id | name | referee_id |
+----+------+------------+
| 1 | Will | null |
| 2 | Jane | null |
| 3 | Alex | 2 |
| 4 | Bill | null |
| 5 | Zack | 1 |
| 6 | Mark | 2 |
+----+------+------------+
Output:
+------+
| name |
+------+
| Will |
| Jane |
| Bill |
| Zack |
+------+
✏️ 풀이
import pandas as pd
def find_customer_referee(customer: pd.DataFrame) -> pd.DataFrame:
return customer[(customer['referee_id'] != 2) | (customer['referee_id'].isna())][['name']]
2가 아닌 것만 찾으면 될 줄 알았는데 null값은 isna()로 찾아줘야 원하는 결과값이 나온다
'[코딩테스트] > [Pandas]' 카테고리의 다른 글
[LeetCode - Pandas] (Easy) 511. Game Play Analysis I (0) | 2025.05.05 |
---|---|
[LeetCode - Pandas] (Easy) 577. Employee Bonus (0) | 2025.05.02 |
[LeetCode - Pandas] (Easy) 586. Customer Placing the Largest Number of Orders (0) | 2025.04.30 |
[LeetCode - Pandas] (Easy) 595. Big Countries (0) | 2025.04.29 |
[LeetCode - Pandas] (Easy) 596. Classes More Than 5 Students (0) | 2025.04.29 |