A simple list of dictionaries without nesting can be easily converted to a pandas dataframe in a single line of python code. This won’t work with nested dictionaries.

The sample code is given below.

import pandas as pd

data = [{'name': 'amal', 'age':30, 'place':'kerala'},
        {'name': 'arun', 'age': 31, 'place': 'karnataka'},
        {'name': 'arjun', 'age': 32, 'place': 'delhi'}
        ]

df = pd.DataFrame(data)
print(type(df))
print(df.head())

I hope this tip is helpful.

Advertisement