Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

How to create DataFrame from a dictionary in Python?

  • Sanjay KumarSanjay Kumar
  • July 5, 2021
  • Pandas
How to create DataFrame from a dictionary in Python?

Hello there! In this tutorial, we are going to discuss the different ways to create a Pandas DataFrame object from a dictionary in Python. So, let’s get started.


Create a DataFrame from dictionary of lists

In Python, we can easily create a Pandas DataFrame object from a Python dictionary. Let’s learn the different ways to create a pandas DataFrame from a dictionary of lists one by one.

1. Using the pd.DataFrame() function

In this method, we will first create a Python dictionary of lists and pass it to the pd.DataFrame() function. Finally, the pd.DataFrame() function returns a pandas DataFrame object with the data from the dictionary of lists. Let’s implement this through Python code.

# Import pandas module
import pandas as pd 

# Create a Python dictionary of lists
data = {'Name': ['Rajan', 'Raman', 'Deepak', 'David'],
      'Roll': [11, 12, 13, 14],
      'City': ['Agra', 'Pune', 'Delhi', 'Sivan']}

# Create a pandas DataFrame dictionary of lists
# using pd.DataFrame() function
df = pd.DataFrame(data)
print(df)

Output:

Create A DataFrame Using DataFrame Function

2. Using the DataFrame.from_dict() function

Like the previous method, here also we will first create a Python dictionary of lists but pass it to the DataFrame.from_dict() function. Finally, the DataFrame.from_dict() function returns a Pandas DataFrame object with the data from the dictionary of lists. Let’s see how to implement this through Python code.

# Import pandas module
import pandas as pd 

# Create a Python dictionary of lists
data = {'Name': ['Rajan', 'Raman', 'Deepak', 'David'],
      'Roll': [11, 12, 13, 14],
      'Marks': [93, 88, 95, 75],
      'City': ['Agra', 'Pune', 'Delhi', 'Sivan']}

# Create a DataFrame from dictionary of lists
# using from_dict() function
df = pd.DataFrame.from_dict(data)
print(df)

Output:

Create A DataFrame Using DataFrame Function

Create a DataFrame from list of dictionaries

In Python, we can also create a Pandas DataFrame object from a list of dictionaries. In this method, we first create a Python list of dictionaries and pass it to the pd.DataFrame() function. Then the pd.DataFrame() function returns a Pandas DataFrame object with the data from the list of dictionaries. Let’s see how to create a DataFrame from a list of dictionaries through Python code.

# Import pandas module
import pandas as pd 

# Create a Python list of dictionaries
data = [{'Name': "Sanjay", 'Roll': 101, 'Branch': 'ECE'},
        {'Name': "Ravi", 'Roll': 102, 'Branch': 'CSE'},
        {'Name': "Thaman", 'Roll': 103, 'Branch': 'EEE'},
        {'Name': "David", 'Roll': 104, 'Branch': 'IPE'},]

# Create a DataFrame from list of dictionaries
# using pd.DataFrame() function
df = pd.DataFrame(data)
print(df)

Output:

Create A DataFrame From List Of Dictionaries

Create a DataFrame from dictionary of Python ranges

In Python, we can even create a Pandas DataFrame object from a dictionary of Python ranges. In this method, we first create a dictionary of ranges using the range() function in Python and pass it to the pd.DataFrame() function. Then the pd.DataFrame() function returns a Pandas DataFrame object with the data from the dictionary of ranges. Let’s see how to create a DataFrame from a dictionary of Python ranges through Python code.

# Import pandas module
import pandas as pd 

# Create a dictionary of
# Python ranges
data = {'Table-1': range(1, 11, 1),
        'Table-2': range(2, 21, 2),
        'Table-3': range(3, 31, 3),
        'Table-4': range(4, 41, 4),
        'Table-5': range(5, 51, 5)}

# Create a DataFrame from a dictionary
# of Python ranges
# using pd.DataFrame() function
df = pd.DataFrame(data)
print(df)

Output:

Create A DataFrame From Dictionary Of Python Ranges

Create a DataFrame from dictionary with user-defined indexes

In Python, we can create a Pandas DataFrame object from a dictionary with user-defined indexes. In this method, we first create a Python dictionary and pass it to the pd.DataFrame() function along with the index list. Then the pd.DataFrame() function returns a Pandas DataFrame object with the data from the dictionary and index from the passed index list. Let’s see how to implement it through Python code.

# Import pandas module
import pandas as pd 

# Create a Python dictionary of lists
data = {'Name': ['Rajan', 'Raman', 'Deepak', 'David'],
      'Roll': [11, 12, 13, 14],
      'Marks': [93, 88, 95, 75],
      'City': ['Agra', 'Pune', 'Delhi', 'Sivan']}

# Create a DataFrame from dictionary of lists
# using pd.DataFrame() function with user-defined indexes
df = pd.DataFrame(data, index = ['S1', 'S2', 'S3', 'S4'])
print(df)

Output:

Create A DataFrame From Dictionary With User Defined Indexes

Conclusion

In this tutorial, we have learned the different ways to create a Pandas DataFrame object from a Python dictionary. Hope you have understood the things discussed above and ready to explore & learn more about pandas DataFrame objects. Stay tuned with us!

Sanjay Kumar
Sanjay Kumar

NITJ | Beta Microsoft Learn Student Ambassador | Technical Content Writer | Python Developer | Linux Enthusiast

Articles: 34
VS Code for Python – A complete Guide to Install and Setup VS Code
Previous Post VS Code for Python - A complete Guide to Install and Setup VS Code
Next Post Regression vs Classification in Machine Learning
Regression vs Classification in Machine Learning

Related Posts

pd.read_json: Read JSON Into a DataFrame

pd.read_json: Read JSON Into a DataFrame

  • November 30, 2026
Pandas to Excel: Export a DataFrame

Pandas to Excel: Export a DataFrame

  • November 24, 2026
Pandas Read Excel: Load a Workbook

Pandas Read Excel: Load a Workbook

  • November 23, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.