我有许多XML文件,它们的结构多样,节点也很多。我想将其放入数据框。这是一个示例:
<?xml version="1.0" encoding="UTF-8"?>
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="3.10">`
<NFe>
<infNFe Id="NFe13180204501136000136550010008074201020771818" versao="3.10">
<ide>
<nNF>807420</nNF>
</ide>
<emit>
<CNPJ>04501136000136</CNPJ>
<IE>041616740</IE>
<CRT>3</CRT>
</emit>
<det nItem="1">
<prod>
<NCM>73170090</NCM>
<CFOP>5405</CFOP>
</prod>
<imposto>
<vTotTrib>38.32</vTotTrib>
<ICMS>
<ICMS60>
<vBCSTRet>0.00</vBCSTRet>
<vICMSSTRet>0.00</vICMSSTRet>
</ICMS60>
</ICMS>
</imposto>
</det>
<det nItem="2">
<prod>
<NCM>73170090</NCM>
<CFOP>5405</CFOP>
</prod>
<imposto>
<vTotTrib>66.92</vTotTrib>
<ICMS>
<ICMS60>
<vBCSTRet>0.00</vBCSTRet>
<vICMSSTRet>2.00</vICMSSTRet>
</ICMS60>
</ICMS>
</imposto>
</det>
</infNFe>
</NFe>
</nfeProc>
输出:
nNF nItem NCM vICMSSTRet
807420 1 73170090 0.00
807420 2 73170090 2.00
我已经尝试过:
import xmltodict
xml_list = []
pathname = './dados/dadosfile/'
for f in os.listdir(pathname):
with open(pathname + f, 'rb') as arquivo:
doc = xmltodict.parse(arquivo)
xml_list.append(doc)
但是,我不知道如何将字典列表放入数据框。
谢谢!