I have a csv that I need to convert to XML using Python. I'm a novice python dev.
Example CSV data:
Amount,Code
CODE50,1246
CODE50,6290
CODE25,1077
CODE25,9790
CODE100,5319
CODE100,4988
Necessary output XML
<coupon-codes coupon-id="CODE50">
<code>1246</code>
<code>1246</code>
<coupon-codes/>
<coupon-codes coupon-id="CODE25">
<code>1077</code>
<code>9790</code>
<coupon-codes/>
<coupon-codes coupon-id="CODE100">
<code>5319</code>
<code>4988</code>
<coupon-codes/>
My guess is I have to use pandas to pull the csv in, use pandas.groupby
to group the Amount
column, then push this into an element/subelement to create the xml, then print/push to a xml file. I can't get the groupby
to work and don't know how to then push that into the element, then populate the sub element.