The 6 AI Engineering Patterns, come build with Greg live:Β Starts Jan 6th, 2025
Leverage
Pandas functions

Pandas DataFrame From Dict – pd.df.from_dict()

Create pandas DataFrame from dictionary using orient options

You can create a DataFrame many different ways. One popular way to do it is creating a pandas DataFrame from dict, or dictionary.

There are two main ways to create a go from dictionary to DataFrame, using orient=columns or orient=index. Orient is short for orientation, or, a way to specify how your data is laid out.

  • Method 1 – Orient (default): columns = If you want the keys of your dictionary to be the DataFrame column names
  • Method 2 – Orient: index = If the keys of your dictionary should be the index values. You’ll need to be explicit about column names.

Pandas DataFrame From Dict

Orient = Columns

You use orient=columns when you want to create a Dataframe from a dictionary who’s keys you want to be the columns. Usually your dictionary values will be a list containing an entry for every row you have.

Check out the picture below to see

Orient = Index

You use orient=Index when you want the values of your dictionary to be the index of your DataFrame. Be sure to specify your columns when creating your DataFrame or else they’ll just be numbers.

Check out the code sample below for an example using both methods to create a pandas dataframe from dict

Reach out if you have any questions about going from a a dict to pandas DataFrame

Link to code

Official Documentation

On this page