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