Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python xml to csv

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET
import pandas as pd

tree = ET.parse("file1.xml")
root = tree.getroot()
iter_root = root.iter()

l = {}
for elem in iter_root:
    l[str(elem.tag)] = str(elem.text)

df = pd.DataFrame.from_dict(l,orient="index")

df.to_csv('ABC.csv')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #xml #csv
ADD COMMENT
Topic
Name
3+1 =