简体   繁体   English

将字典列表导出到excel

[英]Exporting list of dictionaries to excel

i have a list of dictionaries , trying to export it to excel .我有一个字典列表,试图将其导出到 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.我需要将 CI_Name 保留在 .TXT 文件中( here for e:g EB2CMA01 & EB2CMA02 )并从该 .txt 文件中获取这些名称并将其与字典匹配,然后导出该字典的其余键:值以使用KEY 下的相应 VALUE 作为行和列。

You can use pandas for this , for install pandas just > pip install pandas您可以为此使用熊猫,安装熊猫只需> 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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