Convert Python dict to Pandas Dataframe

Pandas DataFrame.from_dict() method allows you to convert Dict to DataFrame object.

Dictionary Keys and Values as DataFrame rows

import pandas as pd import numpy as np myDict = {'key 1': 'value 1', 'key 2': 'value 2', 'key 3': 'value 3'} pd.DataFrame.from_dict(myDict, orient='index', columns=['Values'])
Values key 1 value 1 key 2 value 2 key 3 value 3

Dictionary Keys and Values as DataFrame rows

myDict = {'key 1': 'value 1', 'key 2': 'value 2', 'key 3': 'value 3'} df = pd.DataFrame.from_dict(myDict.items()) df.columns = ['Keys', 'Values'] df

dictionary to dataframe
Keys Values 0 key 1 value 1 1 key 2 value 2 2 key 3 value 3

Dictionary Keys and Values as DataFrame rows

myDict = {'key 1': 'value 1', 'key 2': 'value 2', 'key 3': 'value 3'} pd.DataFrame({'Keys' : myDict.keys() , 'Values' : myDict.values() })
Keys Values 0 key 1 value 1 1 key 2 value 2 2 key 3 value 3

Keys to DataFrame Column and Values to DataFrame Rows

myDict = {'key 1': 'value 1', 'key 2': 'value 2', 'key 3': 'value 3'} df = pd.DataFrame([myDict], columns=myDict.keys()) df
key 1 key 2 key 3 0 value 1 value 2 value 3

Keys to DataFrame Column and Values to DataFrame Rows

df = pd.DataFrame({'Item': ['Item_1', 'Item_2', 'Item_3'], 'Price': [200, 400, 100]}) df
Item Price 0 Item_1 200 1 Item_2 400 2 Item_3 100

Keys to DataFrame Column and Values to DataFrame Rows

dict = [{'Name': 'John', 'Age': 18, 'Marks': 20}, {'Name': 'Doe', 'Age': 19, 'Marks': 25}, {'Name': 'Steve', 'Age': 18, 'Marks': 39 }] df = pd.DataFrame.from_dict(dict) df
Name Age Marks 0 John 18 20 1 Doe 19 25 2 Steve 18 39

Keys to DataFrame Rows and Values to DataFrame columns

dict ={'Name': ['John', 'Doe', 'Steve'], 'Age':[18, 19, 18], 'Marks':[20, 25, 39]} df = pd.DataFrame.from_dict(dict, orient ='index') df

dictionory to pandas dataframe
0 1 2 Name John Doe Steve Age 18 19 18 Marks 20 25 39