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'} |
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 |
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 |
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: