XML tree to a pandas dataframe

Chris Angelico rosuav at gmail.com
Wed Apr 12 14:38:47 EDT 2017


On Thu, Apr 13, 2017 at 12:54 AM, David Shi via Python-list
<python-list at python.org> wrote:
> What is the best way to convert XML document into a pandas dataframe?
> Regards.
> David

I don't know.  What's the least painful way to gouge out my eyes with
a rusty fork?

You're going to need to know the layout of the XML document. Since XML
is not, by nature, a tabular data structure, it's not going to
directly translate into a dataframe (in the way that, say, a CSV file
can). You'll need to figure out what represents a row and what
represents the fields within that row. This will probably involve a
large amount of work parsing the XML file; you can do the low level
heavy lifting with lxml or equivalent, but compiling the parsed data
into rows and columns is all up to you.

In all sincerity I say to you: Good luck.

ChrisA


More information about the Python-list mailing list