datascience.tables.Table.as_text¶
- Table.as_text(max_rows=0, sep=' | ')[source]¶
Format table as text
- Args:
max_rows(int) The maximum number of rows to be present in the converted string of table. (Optional Argument) sep(str) The seperator which will appear in converted string between the columns. (Optional Argument)
- Returns:
String form of the table
The table is just converted to a string with columns seperated by the seperator(argument- default(’ | ‘)) and rows seperated by ‘n’
Few examples of the as_text() method are as follows:
>>> 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_astext = table.as_text() >>> table_astext 'name | age | height\nabc | 12 | 5.5\nxyz | 14 | 6\nuvw | 20 | 5.9'
>>> type(table) <class 'datascience.tables.Table'>
>>> type(table_astext) <class 'str'>
>>> sizes = Table(['size', 'count']).with_rows([ ['small', 50], ['medium', 100], ['big', 50], ]) >>> sizes size | count small | 50 medium | 100 big | 50
>>> sizes_astext = sizes.as_text() >>> sizes_astext 'size | count\nsmall | 50\nmedium | 100\nbig | 50'
>>> sizes_astext = sizes.as_text(1) >>> sizes_astext 'size | count\nsmall | 50\n... (2 rows omitted)'
>>> sizes_astext = sizes.as_text(2, ' - ') >>> sizes_astext 'size - count\nsmall - 50\nmedium - 100\n... (1 rows omitted)'