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

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

0 1 2
Name John Doe Steve
Age 18 19 18
Marks 20 25 39
Related Topics
- Pandas DataFrame: GroupBy Examples
- Pandas DataFrame Aggregation and Grouping
- How to Sort Pandas DataFrame
- Pandas DataFrame: query() function
- Finding and removing duplicate rows in Pandas DataFrame
- How to Replace NaN Values With Zeros in Pandas DataFrame
- How to read CSV File using Pandas DataFrame.read_csv()
- How to Convert Pandas DataFrame to NumPy Array
- How to shuffle a DataFrame rows
- Import multiple csv files into one pandas DataFrame
- Create new column in DataFrame based on the existing columns
- New Pandas dataframe column based on if-else condition
- Rename Pandas columns/index names (labels)