@rplrpl/

CSV to XML 201904

Python

No description

fork
loading
Files
  • main.py
  • fleet_input.csv

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.22937939517570616","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IGx4bWwuZXRyZWUKaW1wb3J0IHBhbmRhcwp4bWxyb290ID0gbHhtbC5ldHJlZS5FbGVtZW50KCdSb290RWxlbWVudCcpCmRmID0gcGFuZGFzLnJlYWRfY3N2KCdmbGVldF9pbnB1dC5jc3YnKQpmb3Igcm93IGluIGRmLnRvX2RpY3Qob3JpZW50PSdyZWNvcmRzJyk6CiAgICBjdXJyZW50X2NhciA9IGx4bWwuZXRyZWUuRWxlbWVudCgnQ2FyJykKICAgIHhtbHJvb3QuYXBwZW5kKGN1cnJlbnRfY2FyKQogICAgZm9yIGNvbG5hbWUsIGNlbGx2YWx1ZSBpbiByb3cuaXRlbXMoKToKICAgICAgICBjdXJyZW50X2Nhci5zZXQoY29sbmFtZSwgY2VsbHZhbHVlKQp3aXRoIG9wZW4oJ2ZsZWV0X291dHB1dC54bWwnLCAnd2InKSBhcyBmaWxlcGF0aDoKICAgIGZpbGVwYXRoLndyaXRlKGx4bWwuZXRyZWUudG9zdHJpbmcoeG1scm9vdCwgcHJldHR5X3ByaW50PVRydWUpKQ=="},"asBuffer":null},"loaded":true}}
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))