Talentd
FleetCode

2879. Display the First Three Rows

Easy93.0% acceptance4 companies
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 1:

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.

Asked at 4 companies

Hints open one at a time

Hint 1
Consider using a built-in function in pandas library to retrieve the initial rows.
1:00
Still stuck?Read 2 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
{"headers":{"employees":["employee_id","name","department","salary"]},"rows":{"employees":[[3,"Bob","Operations",48675],[90,"Alice","Sales",11096],[9,"Tatiana","Engineering",33805],[60,"Annabelle","InformationTechnology",37678],[49,"Jonathan","HumanResources",23793],[43,"Khaled","Administration",40454]]}}
Your code is saved on this device.Solution