pyspark.pandas.DataFrame.to_html

DataFrame.to_html(buf: Optional[IO[str]] = None, columns: Optional[Sequence[Union[Any, Tuple[Any, …]]]] = None, col_space: Union[str, int, Dict[Union[Any, Tuple[Any, …]], Union[str, int]], None] = None, header: bool = True, index: bool = True, na_rep: str = 'NaN', formatters: Union[List[Callable[[Any], str]], Dict[Union[Any, Tuple[Any, …]], Callable[[Any], str]], None] = None, float_format: Optional[Callable[[float], str]] = None, sparsify: Optional[bool] = None, index_names: bool = True, justify: Optional[str] = None, max_rows: Optional[int] = None, max_cols: Optional[int] = None, show_dimensions: bool = False, decimal: str = '.', bold_rows: bool = True, classes: Union[str, list, tuple, None] = None, escape: bool = True, notebook: bool = False, border: Optional[int] = None, table_id: Optional[str] = None, render_links: bool = False) → Optional[str][source]

Render a DataFrame as an HTML table.

Note

This method should only be used if the resulting pandas object is expected to be small, as all the data is loaded into the driver’s memory. If the input is large, set max_rows parameter.

Parameters
bufStringIO-like, optional

Buffer to write to.

columnssequence, optional, default None

The subset of columns to write. Writes all columns by default.

col_spaceint, optional

The minimum width of each column.

headerbool, optional

Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names

indexbool, optional, default True

Whether to print index (row) labels.

na_repstr, optional, default ‘NaN’

String representation of NAN to use.

formatterslist or dict of one-param. functions, optional

Formatter functions to apply to columns’ elements by position or name. The result of each function must be a Unicode string. List must be of length equal to the number of columns.

float_formatone-parameter function, optional, default None

Formatter function to apply to columns’ elements if they are floats. The result of this function must be a Unicode string.

sparsifybool, optional, default True

Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row.

index_namesbool, optional, default True

Prints the names of the indexes.

justifystr, default None

How to justify the column labels. If None uses the option from the print configuration (controlled by set_option), ‘right’ out of the box. Valid values are

  • left

  • right

  • center

  • justify

  • justify-all

  • start

  • end

  • inherit

  • match-parent

  • initial

  • unset.

max_rowsint, optional

Maximum number of rows to display in the console.

max_colsint, optional

Maximum number of columns to display in the console.

show_dimensionsbool, default False

Display DataFrame dimensions (number of rows by number of columns).

decimalstr, default ‘.’

Character recognized as decimal separator, e.g. ‘,’ in Europe.

bold_rowsbool, default True

Make the row labels bold in the output.

classesstr or list or tuple, default None

CSS class(es) to apply to the resulting html table.

escapebool, default True

Convert the characters <, >, and & to HTML-safe sequences.

notebook{True, False}, default False

Whether the generated HTML is for IPython Notebook.

borderint

A border=border attribute is included in the opening <table> tag. By default pd.options.html.border.

table_idstr, optional

A css id is included in the opening <table> tag if specified.

render_linksbool, default False

Convert URLs to HTML links (only works with pandas 0.24+).

Returns
str (or Unicode, depending on data and options)

String representation of the dataframe.

See also

to_string

Convert DataFrame to a string.