[英]Exporting list of dictionaries 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"}]}
我需要將 CI_Name 保留在 .TXT 文件中( here for e:g EB2CMA01 & EB2CMA02
)並從該 .txt 文件中獲取這些名稱並將其與字典匹配,然后導出該字典的其余鍵:值以使用KEY 下的相應 VALUE 作為行和列。
您可以為此使用熊貓,安裝熊貓只需> 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.