Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on October 31, 2019 4:31PM
Likes: 0
Replies: 2
Hi mmc12,
As far as I know, this is not natively supported. However, you can use a python recipe and save your XML file to a folder. The code below illustrates how you can get a handle on a dataset, create a dataframe from it, and then output to XML. I hope it helps!
# -*- coding: utf-8 -*-
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
from lxml import etree as et
# define your inputs, convert non-string columns into strings
test_dataset = dataiku.Dataset("test_dataset")
df = test_dataset.get_dataframe()
df['column_2'] = df['column_2'].astype(str)
root = et.Element('data')
# iterate over rows and add to the tree
for ix, row in df.iterrows():
item = et.SubElement(root, 'item', attrib=row.to_dict());
# get a handle on the folder to write
xml_files = dataiku.Folder("FOLDER_ID")
with xml_files.get_writer("some_output.xml") as w:
w.write(et.tostring(root, encoding='UTF-8', xml_declaration=False))
Nice Code,
Very helpful. Thank you very much.