-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2879-DisplayTheFirstThreeRows.py
More file actions
50 lines (46 loc) · 1.72 KB
/
2879-DisplayTheFirstThreeRows.py
File metadata and controls
50 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 2879. Display the First Three Rows
# 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.
import pandas as pd
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
#return employees[:3]
return employees.head(3)
if __name__ == "__main__":
l = [
[1, 15],
[2, 11],
[3, 11],
[4, 20]
]
print(selectFirstRows(pd.DataFrame(l,columns=["student_id","age"])))