datascience.tables.Table.as_html

Table.as_html(max_rows=0)[source]

Format table as HTML

Args:

max_rows(int) The maximum number of rows to be present in the converted string of table. (Optional Argument)

Returns:

String representing the HTML form of the table

The table is converted to the html format of the table which can be used on a website to represent the table.

Few examples of the as_html() method are as follows. - These examples seem difficult for us to observe and understand since they are in html format, they are useful when you want to display the table on webpages

  1. Simple table being converted to HTML

>>> table = Table().with_columns({'name': ['abc', 'xyz', 'uvw'], 'age': [12,14,20],'height': [5.5,6.0,5.9],})
>>> table
name | age  | height
abc  | 12   | 5.5
xyz  | 14   | 6
uvw  | 20   | 5.9
>>> table_as_html = table.as_html()
>>> table_as_html
'<table border="1" class="dataframe">\n    <thead>\n        <tr>\n            
<th>name</th> <th>age</th> <th>height</th>\n        
</tr>\n    </thead>\n    <tbody>\n        
<tr>\n            <td>abc </td> <td>12  </td> <td>5.5   </td>\n        </tr>\n        
<tr>\n            <td>xyz </td> <td>14  </td> <td>6     </td>\n        </tr>\n        
<tr>\n            <td>uvw </td> <td>20  </td> <td>5.9   </td>\n        </tr>\n    
</tbody>\n</table>'
  1. Simple table being converted to HTML with max_rows passed in

>>> table
name | age  | height
abc  | 12   | 5.5
xyz  | 14   | 6
uvw  | 20   | 5.9
>>> table_as_html_2 = table.as_html(max_rows = 2)
>>> table_as_html_2
'<table border="1" class="dataframe">\n    <thead>\n        <tr>\n            
<th>name</th> <th>age</th> <th>height</th>\n        
</tr>\n    </thead>\n    <tbody>\n        
<tr>\n            <td>abc </td> <td>12  </td> <td>5.5   </td>\n        </tr>\n        
<tr>\n            <td>xyz </td> <td>14  </td> <td>6     </td>\n        </tr>\n    
</tbody>\n</table>\n<p>... (1 rows omitted)</p>'