How to handle missing data in xml file?

Viewed 312

I am parsing csv files to xml files using pandas.

This is how I am currently handling columns missing from my dataframe df:

if field in df.columns:
    ...
    # Assign a value to the xml element
    ...
else:
    xml_data.append('<{0}>{1}</{0}>'.format(field_name, -999))

So for instance, assuming that column (field) Diameter does not exist in my dataframe, the output xml data would contain the following element:

'<Diameter>-999</Diameter>'

Is there a better way of handling this? Does the xml format support NaN values?

0 Answers
Related