VOOZH about

URL: https://www.geeksforgeeks.org/python/make-a-pandas-dataframe-with-two-dimensional-list-python/

⇱ Make a Pandas DataFrame with Two-dimensional List - Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Make a Pandas DataFrame with Two-dimensional List - Python

Last Updated : 29 Sep, 2025

If you already have data stored as a two-dimensional list (a list inside another list, like a table), you can turn it into a Pandas DataFrame so it’s easier to view, label, and work with similar to working in Excel.

Using pd.DataFrame()

The pd.DataFrame() method is most direct way to create a DataFrame. You pass a 2D list directly to the constructor and can optionally provide column names.

Example: In this example, a DataFrame is created from a 2D list with columns "Tag" and "number".

Output

Tag number
0 Geek 25
1 is 30
2 for 26
3 Geeksforgeeks 22

Using pd.DataFrame.from_records()

The from_records() method is designed for structured or record-oriented data. Each inner list of the 2D list is treated as a record (row) and column names can be explicitly provided.

Example: This code creates a DataFrame from a 2D list with columns "Name", "Age" and "Occupation".


Output
 Name Age Occupation
0 Geek1 28 Analyst
1 Geek2 35 Manager
2 Geek3 29 Developer

Using pd.DataFrame.from_dict()

from_dict() creates a DataFrame from a dictionary where keys become column names and values are the column data. A 2D list can be transposed using zip(*data) to convert rows into columns before creating the dictionary.

Example: Here we create a DataFrame from a 2D list using from_dict() and specify column names "Name", "Age" and "Occupation".


Output
 Name Age Occupation
0 Geek1 26 Scientist
1 Geek2 31 Researcher
2 Geek3 24 Engineer

Creating a DataFrame with Specified Data Types

This approach allows you to explicitly define column names and control the structure of the DataFrame. It is suitable for datasets where consistent column labeling and type handling are important.

Example: This program creates a DataFrame from a 2D list with columns "FName", "LName" and "Age".


Output
 FName LName Age
0 Geek1 Reacher 25
1 Geek2 Pete 30
2 Geek3 Wilson 26
3 Geek4 Williams 22
Comment