xxxxxxxxxx
# Python code demonstrate how to create
# Pandas DataFrame by lists of dicts.
import pandas as pd
# Initialise data to lists.
data = [{'Geeks': 'dataframe', 'For': 'using', 'geeks': 'list'},
{'Geeks':10, 'For': 20, 'geeks': 30}]
# Creates DataFrame.
df = pd.DataFrame(data)
# Print the data
df
xxxxxxxxxx
df = pd.DataFrame({'Name': ['John', 'Sara','Peter','Cecilia'],
'Age': [38, 47,63,28],
'City':['Boston', 'Charlotte','London','Memphis']})
datadict = df.to_dict('records')
xxxxxxxxxx
# Supposing d is your list of dicts, simply
df = pd.DataFrame(d)
# Note: this does not work with nested data
xxxxxxxxxx
#Supposing d is your list of dicts, simply:
import pandas as pd
df = pd.DataFrame(d)
xxxxxxxxxx
In [20]: timeit df.T.to_dict().values()
1000 loops, best of 3: 395 µs per loop
In [21]: timeit df.to_dict('records')
10000 loops, best of 3: 53 µs per loop