Skip to content

2877. Create a DataFrame from List

DataFrame players

Column NameType
player_idint
nameobject
ageint
positionobject
......

Instructions

  • 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

Input:

player_idnameagepositionteam
846Mason21ForwardRealMadrid
749Riley30WingerBarcelona
155Bob28StrikerManchesterUnited
583Isabella32GoalkeeperLiverpool
388Zachary24MidfielderBayernMunich
883Ava23DefenderChelsea
355Violet18StrikerJuventus
247Thomas27StrikerParisSaint-Germain
761Jack33MidfielderManchesterCity
642Charlie36Center-backArsenal

Output:

plaintext
[10, 5]

Explanation:

This DataFrame contains 10 rows and 5 columns.

Submissions

python
import pandas as pd

def getDataframeSize(players: pd.DataFrame) -> List[int]:
    return list(players.shape)

Explanation

Python (Pandas)
Submitted by @noeyislearning
  • import pandas as pd: Import the pandas library to work with DataFrames.
  • def getDataframeSize(players: pd.DataFrame) -> List[int]:: Define a function called getDataframeSize that takes a DataFrame players as input and returns a list of integers.
  • return list(players.shape): Return the shape of the DataFrame players as a list.