Display the First Three Rows — LeetCode 2879 Python Solution
EasyPandas
- Problem
- #2879
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
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
SQL
DataFrame: employees
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| employee_id | int |
| name | object |
| department | object |
| salary | int |
+-------------+--------+Python solution
Python
import pandas as pd
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
return employees.head(3)Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
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.