For example, the following nested dictionary lists are listed:
a = [ {'info' : {'name' : 'hahaha', 'status' : 'True'} , 'price' : 500} ]
I'd like to change it to the following data frame.
'name' 'status' 'price'
0 hahaha True 500
How do I make the code?
df = pd.DataFrame(data=a, columns=['?', '?', 'price'])
Is there a way to specify the key value of the nested dictionary immediately when specifying columns
python dataframe dictionary list pandas
>>> a
[{'info': {'name': 'hahaha', 'status': 'True'}, 'price': 500}]
>>> a_ = [ { **d["info"], "price":d["price"] } for d in a ]
>>> a_
[{'name': 'hahaha', 'status': 'True', 'price': 500}]
>>> df = pd.DataFrame(a_)
>>> df
name status price
0 hahaha True 500
© 2024 OneMinuteCode. All rights reserved.