pandas.DataFrame.to_html

pandas 3.1.1 · DataFrame · method

Render the receiver as an HTML table. A Styler includes applicable styling rules in its output.

Call syntax

DataFrame.to_html(…) Full signature
DataFrame.to_html(
    buf=None,
    *,
    columns=None,
    col_space=None,
    header=True,
    index=True,
    na_rep='NaN',
    formatters=None,
    float_format=None,
    sparsify=None,
    index_names=True,
    justify=None,
    max_rows=None,
    max_cols=None,
    show_dimensions=False,
    decimal='.',
    bold_rows=True,
    classes=None,
    escape=True,
    notebook=False,
    border=None,
    table_id=None,
    render_links=False,
    encoding=None,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
buf Optional
Positional or keyword
Default None
str, Path or StringIO-like

Supply a destination file-like buffer, or use the default to return or print the output as documented.

columns Optional
Keyword only
Default None
array-like

Supply column labels or control how columns are handled.

col_space Optional
Keyword only
Default None
str or int, list or dict of int or str
header Optional
Keyword only
Default True
bool

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

index Optional
Keyword only
Default True
bool

Supply row labels or control how existing row labels are used.

na_rep Optional
Keyword only
Default 'NaN'
str

Choose the text used to display missing values.

formatters Optional
Keyword only
Default None
list, tuple or dict of one-param. functions

Pass per-column or per-value formatting functions.

float_format Optional
Keyword only
Default None
one-parameter function

Provide a format string or callable to control numeric display.

sparsify Optional
Keyword only
Default None
bool
index_names Optional
Keyword only
Default True
bool
justify Optional
Keyword only
Default None
str
max_rows Optional
Keyword only
Default None
int
max_cols Optional
Keyword only
Default None
int

Limit the columns included in the displayed summary.

show_dimensions Optional
Keyword only
Default False
bool
decimal Optional
Keyword only
Default '.'
str

Identify the character used as the decimal mark.

bold_rows Optional
Keyword only
Default True
bool
classes Optional
Keyword only
Default None
str or list or tuple
escape Optional
Keyword only
Default True
bool

Control escaping of reserved output characters.

notebook Optional
Keyword only
Default False
{True, False}
border Optional
Keyword only
Default None
int or bool
table_id Optional
Keyword only
Default None
str
render_links Optional
Keyword only
Default False
bool
encoding Optional
Keyword only
Default None
str

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

Returns

str or None