I have df that I turn into a python dictionary, then convert it to an xml format.
Column A | Column B |
---|---|
getTitle | status |
getTitle | timestamp |
submitBook | title |
submitBook | date |
submitBook | numPages |
I used:
`book_df = df.groupby(['Column A'])\
.agg(lambda x: list(x)).to_dict()`
This yields:
{'getTitle': ['status','timestamp'],
'submitBook': ['title', 'date', numPages]}
Thank you.
My attempts to use recursion to turn it into an xml:
def create_tree(root, dict):
for k, v in dict_tree.items():
create_xml_tree(ET.SubElement(root, k), v)
return root
YIELDS THIS RESULT:
<?xml version="1.0" ?>
<Books>
<getTitle>['status','timestamp']</getTitle>
<submitBook>['title', 'date', numPages]</submitBook>
</Books>
But I want the below result where all the keys are a child node and its children are the list of values.
<?xml version="1.0" ?>
<Books>
<getTitle>
<status></status>
<timestamp></timestamp>
</getTitle>
<submitBook>
<title></title>
<date></date>
<numPages></numPages>
</submitBook>
</Books>