Get the Size of a DataFrame — LeetCode 2878 Python Solution

EasyPandas
Problem
#2878
Reading time
2 min

Table schema

SQL
DataFrame players: +-------------+--------+ | Column Name | Type | +-------------+--------+ | player_id | int | | name | object | | age | int | | position | object | | ... | ...

Example

SQL
DataFrame players:
+-------------+--------+
| Column Name | Type   |
+-------------+--------+
| player_id   | int    |
| name        | object |
| age         | int    |
| position    | object |
| ...         | ...    |
+-------------+--------+

Python solution

Python
import pandas as pd


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

Complexity

MeasureComplexity
TimeO(n)
SpaceO(1) to O(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 2878. Get the Size of a DataFrame?
LeetCode 2878. Get the Size of a DataFrame is rated Easy on LeetCode.
What topics does LeetCode 2878. Get the Size of a DataFrame cover?
LeetCode 2878. Get the Size of a DataFrame is tagged Pandas on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview