python xml to csv

Solutions on MaxInterview for python xml to csv by the best coders in the world

showing results for - "python xml to csv"
Isabella
17 Oct 2020
1try:
2    import xml.etree.cElementTree as ET
3except ImportError:
4    import xml.etree.ElementTree as ET
5import pandas as pd
6
7tree = ET.parse("file1.xml")
8root = tree.getroot()
9iter_root = root.iter()
10
11l = {}
12for elem in iter_root:
13    l[str(elem.tag)] = str(elem.text)
14
15df = pd.DataFrame.from_dict(l,orient="index")
16
17df.to_csv('ABC.csv')
18