7.17.2.5. 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 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.

Sample uses:

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() )
Parameters:

data : list of lists or 2d array (not matrix!)

R rows by K columns of table elements

headers : list (or tuple) of str

sequence of K strings, one per header

stubs : list (or tuple) of str

sequence of R strings, one per stub

title : string

title of the table

datatypes : list of int

indexes to data_fmts

txt_fmt : dict

text formatting options

ltx_fmt : dict

latex formatting options

csv_fmt : dict

csv formatting options

hmtl_fmt : dict

hmtl formatting options

celltype : class

the cell class for the table (default: Cell)

rowtype : class

the row class for the table (default: Row)

fmt_dict : dict

general formatting options

__init__(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]
Parameters:

data : list of lists or 2d array (not matrix!)

R rows by K columns of table elements

headers : list (or tuple) of str

sequence of K strings, one per header

stubs : list (or tuple) of str

sequence of R strings, one per stub

title : string

title of the table

datatypes : list of int

indexes to data_fmts

txt_fmt : dict

text formatting options

ltx_fmt : dict

latex formatting options

csv_fmt : dict

csv formatting options

hmtl_fmt : dict

hmtl formatting options

celltype : class

the cell class for the table (default: Cell)

rowtype : class

the row class for the table (default: Row)

fmt_dict : dict

general formatting options

Methods

__init__(data[, headers, stubs, title, ...])
Parameters:
append L.append(object) – append object to end
as_csv(**fmt_dict) Return string, the table in CSV format.
as_html(**fmt_dict) Return string.
as_latex_tabular([center]) Return string, the table as a LaTeX tabular environment.
as_text(**fmt_dict) Return string, the table as text.
count(...)
extend L.extend(iterable) – extend list by appending elements from the iterable
extend_right(table) Return None.
get_colwidths(output_format, **fmt_dict) Return list, the widths of each column.
index((value, [start, ...) Raises ValueError if the value is not present.
insert(idx, row[, datatype]) Return None.
insert_header_row(rownum, headers[, dec_below]) Return None.
insert_stubs(loc, stubs) Return None.
label_cells(func) Return None.
pad(s, width, align) DEPRECATED: just use the pad function
pop(...) Raises IndexError if list is empty or index is out of range.
remove L.remove(value) – remove first occurrence of value.
reverse L.reverse() – reverse IN PLACE
sort L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE;

Attributes

data