Display the First Three Rows - Problem
You are given a DataFrame named employees with the following structure:
| Column Name | Type |
|---|---|
| employee_id | int |
| name | object |
| department | object |
| salary | int |
Write a solution to display the first 3 rows of this DataFrame.
Note: This is a Pandas DataFrame operation problem.
Input & Output
Example 1 — Basic Employee Data
$
Input:
employees = [{"employee_id": 1, "name": "John", "department": "Engineering", "salary": 75000}, {"employee_id": 2, "name": "Sarah", "department": "Marketing", "salary": 65000}, {"employee_id": 3, "name": "Mike", "department": "Sales", "salary": 55000}, {"employee_id": 4, "name": "Lisa", "department": "HR", "salary": 60000}]
›
Output:
[{"employee_id": 1, "name": "John", "department": "Engineering", "salary": 75000}, {"employee_id": 2, "name": "Sarah", "department": "Marketing", "salary": 65000}, {"employee_id": 3, "name": "Mike", "department": "Sales", "salary": 55000}]
💡 Note:
The first 3 rows are returned: John (Engineering), Sarah (Marketing), and Mike (Sales)
Example 2 — Exactly 3 Rows
$
Input:
employees = [{"employee_id": 10, "name": "Alice", "department": "IT", "salary": 80000}, {"employee_id": 20, "name": "Bob", "department": "Finance", "salary": 70000}, {"employee_id": 30, "name": "Carol", "department": "Operations", "salary": 62000}]
›
Output:
[{"employee_id": 10, "name": "Alice", "department": "IT", "salary": 80000}, {"employee_id": 20, "name": "Bob", "department": "Finance", "salary": 70000}, {"employee_id": 30, "name": "Carol", "department": "Operations", "salary": 62000}]
💡 Note:
When DataFrame has exactly 3 rows, all rows are returned
Example 3 — Less than 3 Rows
$
Input:
employees = [{"employee_id": 100, "name": "David", "department": "Research", "salary": 85000}, {"employee_id": 101, "name": "Eve", "department": "Design", "salary": 72000}]
›
Output:
[{"employee_id": 100, "name": "David", "department": "Research", "salary": 85000}, {"employee_id": 101, "name": "Eve", "department": "Design", "salary": 72000}]
💡 Note:
When DataFrame has less than 3 rows, all available rows are returned
Constraints
- DataFrame contains at least 0 rows
- Each row has employee_id, name, department, and salary columns
- employee_id is a positive integer
- salary is a non-negative integer
Visualization
Tap to expand
Understanding the Visualization
1
Input DataFrame
Employee data with multiple rows and columns
2
Apply head(3)
Use Pandas head() method to get first 3 rows
3
Output
DataFrame containing only the first 3 rows
Key Takeaway
🎯 Key Insight: Use df.head(3) - it's the standard, readable way to get the first N rows in Pandas
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code