pandas.read_html

pandas 3.1.1 · Input and output · function

Extract matching HTML tables and return a list of DataFrames.

Call syntax

pd.read_html(…) Full signature
pd.read_html(
    io,
    *,
    match='.+',
    flavor=None,
    header=None,
    index_col=None,
    skiprows=None,
    attrs=None,
    parse_dates=False,
    thousands=',',
    encoding=None,
    decimal='.',
    converters=None,
    na_values=None,
    keep_default_na=True,
    displayed_only=True,
    extract_links=None,
    dtype_backend=…,
    storage_options=None,
)

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

ParameterRequirementAccepted values and behavior
io Required
Positional or keyword
str, path object, or file-like object
match Optional
Keyword only
Default '.+'
str or compiled regular expression
flavor Optional
Keyword only
Default None
{"lxml", "html5lib", "bs4"} or list-like
header Optional
Keyword only
Default None
int or list-like

Define which row or rows provide column names, or control whether to write them.

index_col Optional
Keyword only
Default None
int or list-like

Identify the column or columns whose values should become the row index.

skiprows Optional
Keyword only
Default None
int, list-like or slice

Skip selected input rows before creating the DataFrame.

attrs Optional
Keyword only
Default None
dict
parse_dates Optional
Keyword only
Default False
bool

Choose whether to interpret selected fields as dates during a read.

thousands Optional
Keyword only
Default ','
str

Identify the character separating groups of digits.

encoding Optional
Keyword only
Default None
str

Name a text encoding such as "utf-8".

decimal Optional
Keyword only
Default '.'
str

Identify the character used as the decimal mark.

converters Optional
Keyword only
Default None
dict

Map column labels or positions to conversion functions.

na_values Optional
Keyword only
Default None
iterable

Add input markers that should be interpreted as missing.

keep_default_na Optional
Keyword only
Default True
bool

Choose whether pandas' built-in missing strings are recognized along with custom markers.

displayed_only Optional
Keyword only
Default True
bool
extract_links Optional
Keyword only
Default None
{None, "all", "header", "body", "footer"}
dtype_backend Optional
Keyword only
{'numpy_nullable', 'pyarrow'}

Choose nullable NumPy-backed dtypes or Arrow-backed dtypes.

storage_options Optional
Keyword only
Default None
dict

Pass storage-backend options such as connection settings or HTTP headers.

Returns

dfs

Example for a local Python session

import pandas as pd
from io import StringIO
import lxml
print(pd.read_html(StringIO("<table><tr><th>units</th></tr><tr><td>2</td></tr></table>"))[0])