我有一个字典列表,试图将其导出到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导出为excel在KEY下的相应VALUE为行和列。
答案 0 :(得分:0)
您可以为此使用pandas,只需> pip install pandas即可安装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')