statsmodels.iolib.table.SimpleTable#

class statsmodels.iolib.table.SimpleTable(data, headers=None, stubs=None, title='', datatypes=None, csv_fmt=None, txt_fmt=None, ltx_fmt=None, html_fmt=None, celltype=None, rowtype=None, **fmt_dict)[source]#

Produce a simple ASCII, CSV, HTML, or LaTeX table

Constructed from a rectangular (2d!) array of data, not necessarily numerical. Directly supports at most one header row, which should be the length of data[0]. Directly supports at most one stubs column, which must be the length of data. (But see insert_stubs method.) See globals default_txt_fmt, default_csv_fmt, default_html_fmt, and default_latex_fmt for formatting options.

Attributes:
data

list of list : The data of each row in the table

Methods

append(object, /)

Append object to the end of the list.

as_csv(**fmt_dict)

Return the table in CSV format

as_html(**fmt_dict)

Return the table in HTML format

as_latex_tabular([center])

Return the table as a LaTeX tabular environment

as_text(**fmt_dict)

Return the table as text

clear(/)

Remove all items from list.

copy(/)

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

extend_right(table)

Extend each row of self with the corresponding row of table

get_colwidths(output_format, **fmt_dict)

Return the widths of each column, using a cache

index(value[, start, stop])

Return first index of value.

insert(idx, row[, datatype])

Insert a row into a table

insert_header_row(rownum, headers[, dec_below])

Insert a row of headers

insert_stubs(loc, stubs)

Insert column of stubs at column loc

label_cells(func)

Label cells based on func

pad(s, width, align)

DEPRECATED: just use the pad function

pop([index])

Remove and return item at index (default last).

remove(value, /)

Remove first occurrence of value.

reverse(/)

Reverse IN PLACE.

sort(*[, key, reverse])

Sort the list in ascending order and return None.

Examples

>>> mydata = [[11,12],[21,22]]  # data MUST be 2-dimensional
>>> myheaders = [ "Column 1", "Column 2" ]
>>> mystubs = [ "Row 1", "Row 2" ]
>>> tbl = text.SimpleTable(mydata, myheaders, mystubs, title="Title")
>>> print( tbl )
>>> print( tbl.as_html() )
    # set column specific data formatting
>>> tbl = text.SimpleTable(mydata, myheaders, mystubs, data_fmts=["%3.2f","%d"])
>>> print( tbl.as_csv() )
>>> with open('c:/temp/temp.tex','w') as fh:
...    fh.write( tbl.as_latex_tabular() )

Methods

append(object, /)

Append object to the end of the list.

as_csv(**fmt_dict)

Return the table in CSV format

as_html(**fmt_dict)

Return the table in HTML format

as_latex_tabular([center])

Return the table as a LaTeX tabular environment

as_text(**fmt_dict)

Return the table as text

clear(/)

Remove all items from list.

copy(/)

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

extend_right(table)

Extend each row of self with the corresponding row of table

get_colwidths(output_format, **fmt_dict)

Return the widths of each column, using a cache

index(value[, start, stop])

Return first index of value.

insert(idx, row[, datatype])

Insert a row into a table

insert_header_row(rownum, headers[, dec_below])

Insert a row of headers

insert_stubs(loc, stubs)

Insert column of stubs at column loc

label_cells(func)

Label cells based on func

pad(s, width, align)

DEPRECATED: just use the pad function

pop([index])

Remove and return item at index (default last).

remove(value, /)

Remove first occurrence of value.

reverse(/)

Reverse IN PLACE.

sort(*[, key, reverse])

Sort the list in ascending order and return None.

Properties

data

list of list : The data of each row in the table