Skip to content

2879. Display the First Three Rows

DataFrame employees

Column NameType
employee_idint
nameobject
departmentobject
salaryint

Instructions

  • Write a solution to display the first three rows of employees.

Example

Input:

DataFrame employees

employee_idnamedepartmentsalary
3BobOperations48675
90AliceSales11096
9TatianaEngineering33805
60AnnabelleInformationTechnology37678
49JonathanHumanResources23793
43KhaledAdministration40454

Output:

employee_idnamedepartmentsalary
3BobOperations48675
90AliceSales11096
9TatianaEngineering33805

Explanation:

Only the first 3 rows are displayed.

Submissions

python
import pandas as pd

def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
    return employees.head(3)

Explanation

Python (Pandas)
Submitted by @noeyislearning
  • import pandas as pd: Import the pandas library to work with DataFrames.
  • def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:: Define a function called selectFirstRows that takes a DataFrame employees as input and returns a DataFrame.
  • return employees.head(3): Return the first 3 rows of the DataFrame employees.