-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2878-GetTheSizeOfADataFrame.py
More file actions
54 lines (49 loc) · 1.92 KB
/
2878-GetTheSizeOfADataFrame.py
File metadata and controls
54 lines (49 loc) · 1.92 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
51
52
53
54
# 2878. Get the Size of a DataFrame
# DataFrame players:
# +-------------+--------+
# | Column Name | Type |
# +-------------+--------+
# | player_id | int |
# | name | object |
# | age | int |
# | position | object |
# | ... | ... |
# +-------------+--------+
# Write a solution to calculate and display the number of rows and columns of players.
# Return the result as an array:
# [number of rows, number of columns]
# The result format is in the following example.
# Example 1:
# Input:
# +-----------+----------+-----+-------------+--------------------+
# | player_id | name | age | position | team |
# +-----------+----------+-----+-------------+--------------------+
# | 846 | Mason | 21 | Forward | RealMadrid |
# | 749 | Riley | 30 | Winger | Barcelona |
# | 155 | Bob | 28 | Striker | ManchesterUnited |
# | 583 | Isabella | 32 | Goalkeeper | Liverpool |
# | 388 | Zachary | 24 | Midfielder | BayernMunich |
# | 883 | Ava | 23 | Defender | Chelsea |
# | 355 | Violet | 18 | Striker | Juventus |
# | 247 | Thomas | 27 | Striker | ParisSaint-Germain |
# | 761 | Jack | 33 | Midfielder | ManchesterCity |
# | 642 | Charlie | 36 | Center-back | Arsenal |
# +-----------+----------+-----+-------------+--------------------+
# Output:
# [10, 5]
# Explanation:
# This DataFrame contains 10 rows and 5 columns.
import pandas as pd
from typing import List
def getDataframeSize(players: pd.DataFrame) -> List[int]:
#print(players.shape)
return list(players.shape)
#return [players.shape[0], players.shape[1]]
if __name__ == "__main__":
l = [
[1, 15],
[2, 11],
[3, 11],
[4, 20]
]
print(getDataframeSize(pd.DataFrame(l,columns=["student_id","age"])))