In this post we will be creating a Python script that will convert a list of dictionaries to a Pandas data frame.
See below our list of dictionaries below for this example.
List = [{'Name': 'Harry', 'Age': 23, 'Status': 'Good'},
{'Name': 'Ron', 'Age': 22, 'Status': 'Good'},
{'Name': 'Hermione', 'Age': 22, 'Status': 'Good'},
{'Name': 'Malfoy', 'Age': 23, 'Status': 'Bad'},
{'Name': 'Tom', 'Age': 37, 'Status': 'Bad'},
{'Name': 'Snape', 'Age': 33, 'Status': 'Bad'}]
To convert the above list of dictionaries in to a Pandas data frame we would use the snippet of code below.
import pandas as pd
df = pd.DataFrame(List)
print(df)
The above would return the following as output.
Name Age Status
0 Harry 23 Good
1 Ron 22 Good
2 Hermione 22 Good
3 Malfoy 23 Bad
4 Tom 37 Bad
5 Snape 33 Bad
>>>