简体   繁体   中英

Exporting list of dictionaries to excel

i have a list of dictionaries , trying to export it to excel .

P = {"@odata.context":"https://remedy.data/network","value"[{"CI_Name":"EB2CMA01","Manufacturer":"CiscoSystems","Product_Categorization_Tier1":"HardwareInfrastructure","Product_Categorization_Tier2":"Network","Product_Categorization_Tier3":"Switch","Company":"4584",},{"CI_Name":"EB2CMA02","Manufacturer":"CiscoSystems","Product_Categorization_Tier1":"HardwareInfrastructure","Product_Categorization_Tier2":"Network","Product_Categorization_Tier3":"Switch","Company":"4584"}]}

I need to keep CI_Name in a .TXT file ( here for e:g EB2CMA01 & EB2CMA02 )and take these name from that .txt file and match that against the dictionary and then export the rest of key:value of that dictionary to excel with respective VALUE under the KEY as row &column.

You can use pandas for this , for install pandas just > pip install pandas

import pandas as pd

P = {"@odata.context":"https://remedy.data/network","value":[{"CI_Name":"EB2CMA01","Manufacturer":"CiscoSystems","Product_Categorization_Tier1":"HardwareInfrastructure","Product_Categorization_Tier2":"Network","Product_Categorization_Tier3":"Switch","Company":"4584",},{"CI_Name":"EB2CMA02","Manufacturer":"CiscoSystems","Product_Categorization_Tier1":"HardwareInfrastructure","Product_Categorization_Tier2":"Network","Product_Categorization_Tier3":"Switch","Company":"4584"}]}
df=pd.DataFrame.from_dict(P['value'])
df.to_excel('test.xlsx')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM