pandas.read_xml
pandas 3.1.1 · Input and output · function
Turn elements selected from XML into DataFrame rows and columns.
Call syntax
pd.read_xml(…) Full signature
pd.read_xml(
path_or_buffer,
*,
xpath='./*',
namespaces=None,
elems_only=False,
attrs_only=False,
names=None,
dtype=None,
converters=None,
parse_dates=None,
encoding='utf-8',
parser='lxml',
stylesheet=None,
iterparse=None,
compression='infer',
storage_options=None,
dtype_backend=…,
)Inspect the call
Run this code to inspect the callable and its parameters. Its data, backend, or environment is needed to execute the operation itself.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
path_or_buffer |
Required Positional or keyword |
str, path object, or file-like object |
xpath |
Optional Keyword only Default './*' |
str |
namespaces |
Optional Keyword only Default None |
dict |
elems_only |
Optional Keyword only Default False |
bool |
attrs_only |
Optional Keyword only Default False |
bool |
names |
Optional Keyword only Default None |
list-like Supply explicit names for labels, fields, or levels. |
dtype |
Optional Keyword only Default None |
Type name or dict of column -> type Choose the data type for the input conversion or result. |
converters |
Optional Keyword only Default None |
dict Map column labels or positions to conversion functions. |
parse_dates |
Optional Keyword only Default None |
bool or list of int or names or list of lists or dict Choose whether to interpret selected fields as dates during a read. |
encoding |
Optional Keyword only Default 'utf-8' |
str Name a text encoding such as "utf-8". |
parser |
Optional Keyword only Default 'lxml' |
{'lxml','etree'} |
stylesheet |
Optional Keyword only Default None |
str, path object or file-like object |
iterparse |
Optional Keyword only Default None |
dict |
compression |
Optional Keyword only Default 'infer' |
str or dict Choose whether and how to compress or decompress data. |
storage_options |
Optional Keyword only Default None |
dict Pass storage-backend options such as connection settings or HTTP headers. |
dtype_backend |
Optional Keyword only |
{'numpy_nullable', 'pyarrow'} Choose nullable NumPy-backed dtypes or Arrow-backed dtypes. |
Returns
df
Example for a local Python session
import pandas as pd
from io import StringIO
import lxml
print(pd.read_xml(StringIO("<rows><row><units>2</units></row></rows>")))