Ive’being try to transform all log in a dict through xmltodict.parse function
问题是,当我试图将单行转换为变量时,效果很好
a=xmltodict.parse(df['CONFIG'][0](
与相同
parsed[1]=xmltodict.parse(df['CONFIG'][1](
但是,当我尝试迭代整个数据帧并将其存储在dictionaire上时,我会得到以下
for ind in df['CONFIG'].index:
parsed[ind] = xmltodict.parse(df['CONFIG'][ind])
---------------------------------------------------------------------------
ExpatError Traceback (most recent call last)
/tmp/ipykernel_31/1871123186.py in <module>
1 for ind in df['CONFIG'].index:
----> 2 parsed[ind] = xmltodict.parse(df['CONFIG'][ind])
/opt/conda/lib/python3.9/site-packages/xmltodict.py in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, disable_entities, **kwargs)
325 parser.ParseFile(xml_input)
326 else:
--> 327 parser.Parse(xml_input, True)
328 return handler.item
329
ExpatError: syntax error: line 1, column 0
你能试试这个吗?
for ind in range(len(df['CONFIG'])):
parsed[ind] = xmltodict.parse(df['CONFIG'][ind])