How to create DataFrame from dictionary in Python-Pandas? Last Updated : 20 Feb, 2025 Comments Improve Suggest changes Like Article Like Report The task of converting a dictionary into a Pandas DataFrame involves transforming a dictionary into a structured, tabular format where keys represent column names or row indexes and values represent the corresponding data.Using Default ConstructorThis is the simplest method where a dictionary is directly passed to pd.DataFrame(). Here, dictionary keys become column names and values become the corresponding data. Python import pandas as pd d = { 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'City': ['New York', 'London', 'Paris'] } # creating a Dataframe object df = pd.DataFrame(d) print(df) Output Name Age City 0 Alice 25 New York 1 Bob 30 London 2 Charlie 35 Paris Table of ContentUsing Custom IndexesUsing Simple DictionarySelecting Specific ColumnsUsing Different Orientation (Keys as Indexes)Using Nested DictionaryUsing Custom IndexesBy default, Pandas assigns numerical row indexes (0,1,2,...). however we can define custom indexes using the index parameter. Python import pandas as pd # dictionary with list object in values d = { 'Name' : ['Ankit', 'Aishwarya', 'Shaurya', 'Shivangi'], 'Age' : [23, 21, 22, 21], 'University' : ['BHU', 'JNU', 'DU', 'BHU'], } # creating a Dataframe object from dictionary with custom indexing df = pd.DataFrame(d, index = ['a', 'b', 'c', 'd']) print(df) Output Name Age University a Ankit 23 BHU b Aishwarya 21 JNU c Shaurya 22 DU d Shivangi 21 BHU Using Simple DictionaryWhen the dictionary contains only key-value pairs (instead of lists), we need to convert it into a tabular format using pd.DataFrame(list(dictionary.items())). Python import pandas as pd d = { 'Ankit' : 22, 'Golu' : 21, 'hacker' : 23 } # creating a Dataframe object from a list of tuples of key, value pair df = pd.DataFrame(list(d.items())) print(df) Output 0 1 0 Ankit 22 1 Golu 21 2 hacker 23 Selecting Specific ColumnsWe can create a DataFrame using only the required columns from the dictionary. Python import pandas as pd d = { 'Name' : ['Ankit', 'Aishwarya', 'Shaurya', 'Shivangi'], 'Age' : [23, 21, 22, 21], 'University' : ['BHU', 'JNU', 'DU', 'BHU'], } # creating a Dataframe object with skipping one column i.e skipping age column. df = pd.DataFrame(d, columns = ['Name', 'University']) print(df) Output Name University 0 Ankit BHU 1 Aishwarya JNU 2 Shaurya DU 3 Shivangi BHU Using Different Orientation (Keys as Indexes)By default, dictionary keys act as column names, but we can use them as row indexes by setting orient='index'. Python import pandas as pd # dictionary with list object in values d = { 'Name' : ['Ankit', 'Aishwarya', 'Shaurya', 'Shivangi'], 'Age' : [23, 21, 22, 21], 'University' : ['BHU', 'JNU', 'DU', 'BHU'], } # creating a Dataframe object in which dictionary # key is act as index value and column value is # 0, 1, 2... df = pd.DataFrame.from_dict(d, orient = 'index') print(df) Output 0 1 2 3 Name Ankit Aishwarya Shaurya Shivangi Age 23 21 22 21 University BHU JNU DU BHU Comment More infoAdvertise with us Next Article How to create DataFrame from dictionary in Python-Pandas? ankthon Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads How to convert Dictionary to Pandas Dataframe? Converting a dictionary into a Pandas DataFrame is simple and effective. You can easily convert a dictionary with key-value pairs into a tabular format for easy data analysis. Lets see how we can do it using various methods in Pandas.1. Using the Pandas ConstructorWe can convert a dictionary into Da 2 min read Create pandas dataframe from lists using dictionary Pandas DataFrame is a 2-dimensional labeled data structure like any table with rows and columns. The size and values of the dataframe are mutable, i.e., can be modified. It is the most commonly used pandas object. Creating pandas data-frame from lists using dictionary can be achieved in multiple way 2 min read How to create crosstabs from a Dictionary in Python? In this article, we are going to see how to create crosstabs from dictionaries in Python. The pandas crosstab function builds a cross-tabulation table that can show the frequency with which certain groups of data appear. This method is used to compute a simple cross-tabulation of two (or more) fact 3 min read Convert PySpark DataFrame to Dictionary in Python In this article, we are going to see how to convert the PySpark data frame to the dictionary, where keys are column names and values are column values. Before starting, we will create a sample Dataframe: Python3 # Importing necessary libraries from pyspark.sql import SparkSession # Create a spark se 3 min read Create PySpark dataframe from dictionary In this article, we are going to discuss the creation of Pyspark dataframe from the dictionary. To do this spark.createDataFrame() method method is used. This method takes two argument data and columns. The data attribute will contain the dataframe and the columns attribute will contain the list of 2 min read Create Pandas Dataframe from Dictionary of Dictionaries In this article, we will discuss how to create a pandas dataframe from the dictionary of dictionaries in Python. Method 1: Using DataFrame() We can create a dataframe using Pandas.DataFrame() method. Syntax: pandas.DataFrame(dictionary) where pandas are the module that supports DataFrame data struct 2 min read Python - Convert dict of list to Pandas dataframe In this article, we will discuss how to convert a dictionary of lists to a pandas dataframe. Method 1: Using DataFrame.from_dict() We will use the from_dict method. This method will construct DataFrame from dict of array-like or dicts. Syntax: pandas.DataFrame.from_dict(dictionary) where dictionary 2 min read Create a Pandas Dataframe from a Dict of Equal Length Lists - Python A dictionary of equal-length lists is a common data structure used to store structured data. Pandas allows us to easily convert such dictionaries into DataFrames for further analysis and operations. In this article we will explore how to create a Pandas DataFrame from a dictionary of equal-length li 2 min read How to Create a Dictionary in Python The task of creating a dictionary in Python involves storing key-value pairs in a structured and efficient manner, enabling quick lookups and modifications. A dictionary is an unordered, mutable data structure where each key must be unique and immutable, while values can be of any data type. For exa 3 min read Like