77
77
index_names : bool, optional
78
78
Prints the names of the indexes, default True
79
79
line_width : int, optional
80
- Width to wrap a line in characters, default no wrap"""
80
+ Width to wrap a line in characters, default no wrap
81
+ table_id : str, optional
82
+ id for the <table> element create by to_html
83
+
84
+ .. versionadded:: 0.23.0"""
81
85
82
86
_VALID_JUSTIFY_PARAMETERS = ("left" , "right" , "center" , "justify" ,
83
87
"justify-all" , "start" , "end" , "inherit" ,
@@ -387,7 +391,8 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
387
391
header = True , index = True , na_rep = 'NaN' , formatters = None ,
388
392
justify = None , float_format = None , sparsify = None ,
389
393
index_names = True , line_width = None , max_rows = None ,
390
- max_cols = None , show_dimensions = False , decimal = '.' , ** kwds ):
394
+ max_cols = None , show_dimensions = False , decimal = '.' ,
395
+ table_id = None , ** kwds ):
391
396
self .frame = frame
392
397
if buf is not None :
393
398
self .buf = _expand_user (_stringify_path (buf ))
@@ -413,6 +418,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
413
418
self .max_rows_displayed = min (max_rows or len (self .frame ),
414
419
len (self .frame ))
415
420
self .show_dimensions = show_dimensions
421
+ self .table_id = table_id
416
422
417
423
if justify is None :
418
424
self .justify = get_option ("display.colheader_justify" )
@@ -740,7 +746,8 @@ def to_html(self, classes=None, notebook=False, border=None):
740
746
max_rows = self .max_rows ,
741
747
max_cols = self .max_cols ,
742
748
notebook = notebook ,
743
- border = border )
749
+ border = border ,
750
+ table_id = self .table_id )
744
751
if hasattr (self .buf , 'write' ):
745
752
html_renderer .write_result (self .buf )
746
753
elif isinstance (self .buf , compat .string_types ):
@@ -1082,7 +1089,7 @@ class HTMLFormatter(TableFormatter):
1082
1089
indent_delta = 2
1083
1090
1084
1091
def __init__ (self , formatter , classes = None , max_rows = None , max_cols = None ,
1085
- notebook = False , border = None ):
1092
+ notebook = False , border = None , table_id = None ):
1086
1093
self .fmt = formatter
1087
1094
self .classes = classes
1088
1095
@@ -1101,6 +1108,7 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None,
1101
1108
if border is None :
1102
1109
border = get_option ('display.html.border' )
1103
1110
self .border = border
1111
+ self .table_id = table_id
1104
1112
1105
1113
def write (self , s , indent = 0 ):
1106
1114
rs = pprint_thing (s )
@@ -1220,8 +1228,11 @@ def write_result(self, buf):
1220
1228
self .write ('<div{style}>' .format (style = div_style ))
1221
1229
1222
1230
self .write_style ()
1223
- self .write ('<table border="{border}" class="{cls}">'
1224
- .format (border = self .border , cls = ' ' .join (_classes )), indent )
1231
+ id_section = ' id="{table_id}"' .format (table_id = self .table_id )\
1232
+ if self .table_id is not None else ""
1233
+ self .write ('<table border="{border}" class="{cls}"{id_section}>'
1234
+ .format (border = self .border , cls = ' ' .join (_classes ),
1235
+ id_section = id_section ), indent )
1225
1236
1226
1237
indent += self .indent_delta
1227
1238
indent = self ._write_header (indent )
0 commit comments