pandas-read-xml (Legacy)

0.3.1 · maintenance · verified Wed Apr 15

This library, `pandas-read-xml`, provides functionality to read XML files directly into pandas DataFrames. It aims to simplify the process of converting hierarchical XML data into a tabular format, offering options for path specification and automatic flattening. It is important to note that `pandas.read_xml` was introduced into the core pandas library in version 1.3.0, largely superseding the need for this standalone package for newer pandas installations. The latest version of this standalone library is 0.3.1.

Warnings

Install

Imports

Quickstart

Reads a simple XML string or file path into a pandas DataFrame. The second argument specifies the 'root key list' to navigate to the desired data elements.

import pandas_read_xml as pdx
import io

xml_data = """<?xml version='1.0' encoding='utf-8'?>
<root>
    <item id="1">
        <name>Apple</name>
        <price>1.00</price>
    </item>
    <item id="2">
        <name>Banana</name>
        <price>0.50</price>
    </item>
</root>"""

# To read from a file, replace io.StringIO(xml_data) with 'path/to/your/file.xml'
df = pdx.read_xml(io.StringIO(xml_data), ['root', 'item'])
print(df)

view raw JSON →