Answers for "python xml to csv"

0

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')
Posted by: Guest on July-05-2021

Python Answers by Framework

Browse Popular Code Answers by Language