EasyNo. 2879
Display the First Three Rows — LeetCode 2879 Python Solution
- Topics
- Pandas
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
DataFrame: employees +-------------+--------+ | Column Name | Type | +-------------+--------+ | employee_id | int | | name | object | | department | object | | salary | int | +-------------+--------+ Write a solution to display the first 3 rows of this DataFrame.Example
DataFrame: employees
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| employee_id | int |
| name | object |
| department | object |
| salary | int |
+-------------+--------+Python solution
import pandas as pd
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
return employees.head(3)Complexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2877 | Create a DataFrame from List | Easy |
| 2874 | Maximum Value of an Ordered Triplet II | Medium |
| 2873 | Maximum Value of an Ordered Triplet I | Easy |
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
Frequently asked questions
- How hard is LeetCode 2879. Display the First Three Rows?
LeetCode 2879. Display the First Three Rows is rated Easy on LeetCode.
- What topics does LeetCode 2879. Display the First Three Rows cover?
LeetCode 2879. Display the First Three Rows is tagged Pandas on LeetCode.