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
582 PHP ssh2_scp_send fails to send files as intended
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.