2879. Display the First Three Rows
DataFrame employees
Column Name | Type |
---|---|
employee_id | int |
name | object |
department | object |
salary | int |
Instructions
- Write a solution to display the first three rows of
employees
.
Example
Input:
DataFrame employees
employee_id | name | department | salary |
---|---|---|---|
3 | Bob | Operations | 48675 |
90 | Alice | Sales | 11096 |
9 | Tatiana | Engineering | 33805 |
60 | Annabelle | InformationTechnology | 37678 |
49 | Jonathan | HumanResources | 23793 |
43 | Khaled | Administration | 40454 |
Output:
employee_id | name | department | salary |
---|---|---|---|
3 | Bob | Operations | 48675 |
90 | Alice | Sales | 11096 |
9 | Tatiana | Engineering | 33805 |
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 calledselectFirstRows
that takes a DataFrameemployees
as input and returns a DataFrame.return employees.head(3)
: Return the first 3 rows of the DataFrameemployees
.