Create a DataFrame from List — LeetCode 2877 Python Solution

EasyPandas
Problem
#2877
Reading time
2 min

The problem

Write a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.

Example

Input
student_data:
Output
+------------+-----+
Explanation
A DataFrame was created on top of student_data, with two columns named student_id and age.

Python solution

Python
import pandas as pd


def createDataframe(student_data: List[List[int]]) -> pd.DataFrame:
    return pd.DataFrame(student_data, columns=['student_id', 'age'])

Complexity

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

Related problems

Frequently asked questions

How hard is LeetCode 2877. Create a DataFrame from List?
LeetCode 2877. Create a DataFrame from List is rated Easy on LeetCode.
What topics does LeetCode 2877. Create a DataFrame from List cover?
LeetCode 2877. Create a DataFrame from List 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