I am new to XML Element Tree and I am wondering how to properly convert the values I have in a pandas dataframe into XML values.
Here is a sample of what the values of my dataframe look like:
Id Email State Country LastName
Mjkx sealover71@yahoo.com CA United States Withers
I know what I have below probably isn't close to working but I figured what I want to happen is possible with df.iterrows(). How do I create XML values for each column in my dataframe with XML Element Tree?
for row in df.iterrows():
id = ET.SubElement('ID', 'id')
lastname = ET.SubElement('LastName', 'lastname')
email = ET.SubElement('Email', 'email')
state = ET.SubElement('State', 'state')
country = ET.SubElement('Country', 'country')
print(ET.tostring(row, pretty_print=True).decode('utf-8'))
Here is what the desired output should look like to post into our crm:
<crc>
<lead>
<id>Mjkx</id>
<lastname>Withers</lastname>
<email>sealover71@yahoo.com</email>
<state>CA</state>
<country>United States</country>
</lead>
</crc>
Thanks for your help!