Create a DataFrame from List — LeetCode 2877 Python Solution
EasyPandas
- Problem
- #2877
- Reading time
- 2 min
- Source
- leetcode.com
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
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(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.