Convert Dictionary Value list to list of dictionaries code example
Example 1: python How to convert a dictionary of dictionaries nested dictionary to a Pandas dataframe
dataframe = pd.DataFrame(nested_dictionary)
dataframe = dataframe.transpose()
import pandas as pd
student_data = {
0 : {
'name' : 'Aadi',
'age' : 16,
'city' : 'New york'
},
1 : {
'name' : 'Jack',
'age' : 34,
'city' : 'Sydney'
},
2 : {
'name' : 'Riti',
'age' : 30,
'city' : 'Delhi'
}
}
pandas_dataframe = pd.DataFrame(student_data)
print(pandas_dataframe)
0 1 2
age 16 34 30
city New york Sydney Delhi
name Aadi Jack Riti
pandas_dataframe.transpose()
age city name
0 16 New york Aadi
1 34 Sydney Jack
2 30 Delhi Riti
Example 2: python convert string to list of dictionaries
import json
with open('.listOfDicts.txt', 'r') as file:
dataList = json.loads(file.read().replace('\n', ''))
for dictItem in dataList:
for key , val in dictItem.items():
print( key , val )