pandas.DataFrame.to_html
参数
buf str, Path 或 StringIO-like, 可选, 默认无
要写入的缓冲区。如果没有,则输出作为字符串返回。
列序列,可选,默认无
要写入的列子集。默认写入所有列。
col_space str 或 int,int 或 str 的列表或字典,可选
以 CSS 长度单位表示的每列的最小宽度。假设 int 是 px 单位。
0.25.0 新版功能:能够使用 str.
标头布尔值,可选
是否打印列标签,默认为True。
索引布尔值,可选,默认为 True
是否打印索引(行)标签。
na_rep str,可选,默认’NaN’
NaN要使用的字符串表示形式。
一个参数的格式化列表、元组或字典。功能,可选
按位置或名称应用于列元素的格式化函数。每个函数的结果必须是一个 unicode 字符串。列表/元组的长度必须等于列数。
float_format单参数函数,可选,默认无
如果它们是浮点数,则应用于列元素的格式化函数。此函数必须返回一个 unicode 字符串,并且将仅应用于非NaN元素,NaN由na_rep.
在 1.2.0 版中更改。
稀疏布尔值,可选,默认为 True
对于具有分层索引的 DataFrame 设置为 False 以在每行打印每个多索引键。
index_names bool,可选,默认为 True
打印索引的名称。
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)[source]
Render a DataFrame as an HTML table.
Parameters
bufstr, Path or StringIO-like, optional, default None
Buffer to write to. If None, the output is returned as a string.
columnssequence, optional, default None
The subset of columns to write. Writes all columns by default.
col_spacestr or int, list or dict of int or str, optional
The minimum width of each column in CSS length units. An int is assumed to be px units.
New in version 0.25.0: Ability to use str.
headerbool, optional
Whether to print column labels, default True.
indexbool, optional, default True
Whether to print index (row) labels.
na_repstr, optional, default ‘NaN’
String representation of NaN to use.
formatterslist, tuple 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/tuple 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. This function must return a unicode string and will be applied only to the non-NaN elements, with NaN being handled by na_rep.
Changed in version 1.2.0.
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.
min_rowsint, optional
The number of rows to display in the console in a truncated repr (when number of rows is above max_rows).
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
encodingstr, default “utf-8”
Set character encoding.
New in version 1.0.
table_idstr, optional
A css id is included in the opening
render_linksbool, default False
Convert URLs to HTML links.
Returns
str or None
If buf is None, returns the result as a string. Otherwise returns None.
原文来源