Files
  • main.py
  • fleet_input.csv
main.py
1
2
3
4
5
6
7
8
9
10
11
import lxml.etree
import pandas
xmlroot = lxml.etree.Element('RootElement')
df = pandas.read_csv('fleet_input.csv')
for row in df.to_dict(orient='records'):
    current_car = lxml.etree.Element('Car')
    xmlroot.append(current_car)
    for colname, cellvalue in row.items():
        current_car.set(colname, cellvalue)
with open('fleet_output.xml', 'wb') as filepath:
    filepath.write(lxml.etree.tostring(xmlroot, pretty_print=True))