pandas Creating DataFrames Create a DataFrame from a list of dictionaries


A DataFrame can be created from a list of dictionaries. Keys are used as column names.

import pandas as pd
L = [{'Name': 'John', 'Last Name': 'Smith'}, 
         {'Name': 'Mary', 'Last Name': 'Wood'}]
# Output:  Last Name  Name
# 0     Smith  John
# 1      Wood  Mary

Missing values are filled with NaNs

L = [{'Name': 'John', 'Last Name': 'Smith', 'Age': 37},
     {'Name': 'Mary', 'Last Name': 'Wood'}]
# Output:     Age Last Name  Name
#          0   37     Smith  John
#          1  NaN      Wood  Mary