728x90
DataFrame: employees
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| employee_id | int |
| name | object |
| department | object |
| salary | int |
+-------------+--------+
이 DataFrame의 첫 3개 행을 표시하는 해결책을 작성하세요.
Example 1:
Input:
DataFrame employees
+-------------+-----------+-----------------------+--------+
| employee_id | name | department | salary |
+-------------+-----------+-----------------------+--------+
| 3 | Bob | Operations | 48675 |
| 90 | Alice | Sales | 11096 |
| 9 | Tatiana | Engineering | 33805 |
| 60 | Annabelle | InformationTechnology | 37678 |
| 49 | Jonathan | HumanResources | 23793 |
| 43 | Khaled | Administration | 40454 |
+-------------+-----------+-----------------------+--------+
Output:
+-------------+---------+-------------+--------+
| employee_id | name | department | salary |
+-------------+---------+-------------+--------+
| 3 | Bob | Operations | 48675 |
| 90 | Alice | Sales | 11096 |
| 9 | Tatiana | Engineering | 33805 |
+-------------+---------+-------------+--------+
설명: 첫 3개 행만 표시됩니다.
✏️ 풀이
import pandas as pd
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
return employees.head(3)
'[Study] > [Pandas]' 카테고리의 다른 글
[LeetCode - Pandas] (Easy) 2877. Create a DataFrame from List (0) | 2025.04.03 |
---|---|
[LeetCode - Pandas] (Easy) 2878. Get the Size of a DataFrame (0) | 2025.04.02 |
[LeetCode - Pandas] (Easy) 2880. Select Data (0) | 2025.04.01 |
[LeetCode - Pandas] (Easy) 2881. Create a New Column (2) | 2025.04.01 |
[LeetCode - Pandas] (Easy) 2882. Drop Duplicate Rows (0) | 2025.03.31 |