Create pandas DataFrame from Dictionary in Python (Example Code)

In this Python article you’ll learn how to convert a dictionary to a pandas DataFrame.

Creation of Example Data

x = {'A': 'x',                # Construct example dictionary
     'B': 'y',
     'C': 'z'}
print(x)
# {'A': 'x', 'B': 'y', 'C': 'z'}

Example: Convert Dictionary to pandas DataFrame

import pandas as pd           # Import pandas library to Python
df = pd.DataFrame([x])        # Using DataFrame() function
print(df)
#    A  B  C
# 0  x  y  z

Related Articles & Further Resources

You may find some related Python tutorials on topics such as lists and data conversion below:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top