Display the First Three Rows — LeetCode 2879 Python Solution

EasyPandas
Problem
#2879
Reading time
2 min

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

MeasureComplexity
TimeO(n)
SpaceO(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.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview