Convert DICTIONARY to DATAFRAME, Free
Files convert instantly in your browser. 100% private, any file size, no account needed.
How to convert DICTIONARY to DATAFRAME
In Python, a dictionary is the most natural way to hold labeled data before analysis, but pandas DataFrames are required for operations like groupby, merge, pivot, and plotting. Converting a dictionary to a DataFrame is a daily task for data engineers and analysts, and the exact method depends on the dictionary's structure: flat key-value pairs produce a single-column DataFrame, while a dictionary of lists produces a multi-column table where each key becomes a column name.
This tool generates the correct pandas constructor call for your data structure. Paste a Python dict literal and the converter outputs the pd.DataFrame() invocation with the right orientation parameter, covering the common cases of records (list of dicts), columns (dict of lists), and single-row (flat dict) structures.
Paste your Python dictionary
Enter a dict literal such as {'a': [1,2,3], 'b': [4,5,6]} or a list of dicts like [{'x':1,'y':2}, {'x':3,'y':4}].
Review the detected structure
The tool identifies whether your dict is a column-oriented dict of lists, a list of row records, or a flat single-row dict.
Copy the DataFrame code
The converter outputs the correct pd.DataFrame() call. For column orientation it uses the dict directly; for row records it sets the columns from the first dict's keys.
Run in your Python environment
Paste the code into a Jupyter notebook or script, import pandas as pd, and run it. Print df.head() to verify the structure is what you expected.
Frequently asked questions
What is the simplest way to create a DataFrame from a dictionary of lists?
Use pd.DataFrame({'col1': [1,2,3], 'col2': [4,5,6]}). Each key becomes a column name and each list becomes the column's values. All lists must have the same length.
How do I create a DataFrame from a list of dictionaries?
Use pd.DataFrame([{'a':1,'b':2}, {'a':3,'b':4}]). Pandas aligns values by key name, so uneven keys produce NaN values in missing cells. This is the records format and is the most common for API response data.
What does orient='index' do in pd.DataFrame.from_dict?
It treats the outer keys as row labels (index) rather than column names. pd.DataFrame.from_dict({'row1': [1,2], 'row2': [3,4]}, orient='index', columns=['a','b']) creates a two-row DataFrame.
How do I specify column order when creating a DataFrame from a dict?
Pass the columns argument: pd.DataFrame(my_dict, columns=['b','a']) controls the column order. Without it, Python 3.7+ preserves insertion order from the dict.
Can I create a DataFrame from a nested dictionary?
Yes, using pd.DataFrame.from_dict(nested_dict, orient='index') where the outer keys become the index and inner keys become columns. For deeply nested structures, pd.json_normalize() from pandas is often more appropriate.