Goulib.table module¶
“mini pandas.DataFrame” Table class with Excel + CSV I/O, easy access to columns, HTML output, and much more.
-
class
Goulib.table.Cell(data=None, align=None, fmt=None, tag=None, style={})[source]¶ Bases:
objectTable cell with HTML attributes
Parameters: - data – cell value(s) of any type
- align – string for HTML align attribute
- fmt – format string applied applied to data
- tag – called to build each cell. defaults to ‘td’
- style – dict or string for HTML style attribute
-
__init__(data=None, align=None, fmt=None, tag=None, style={})[source]¶ Parameters: - data – cell value(s) of any type
- align – string for HTML align attribute
- fmt – format string applied applied to data
- tag – called to build each cell. defaults to ‘td’
- style – dict or string for HTML style attribute
-
html(**kwargs)[source]¶ Returns: string HTML formatted cell: - if data is int, default align=”right”
- if data is float, default align=”right” and fmt=’%0.2f’
- if data is
timedelta, align = “right” and formatting is done bydatetime2.strftimedelta()
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__¶ Return repr(self).
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
class
Goulib.table.Row(data, align=None, fmt=None, tag=None, style={})[source]¶ Bases:
objectTable row with HTML attributes
Parameters: - data – (list of) cell value(s) of any type
- align – (list of) string for HTML align attribute
- fmt – (list of) format string applied applied to data
- tag – (list of) tags called to build each cell. defaults to ‘td’
- style – (list of) dict or string for HTML style attribute
-
__init__(data, align=None, fmt=None, tag=None, style={})[source]¶ Parameters: - data – (list of) cell value(s) of any type
- align – (list of) string for HTML align attribute
- fmt – (list of) format string applied applied to data
- tag – (list of) tags called to build each cell. defaults to ‘td’
- style – (list of) dict or string for HTML style attribute
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__¶ Return repr(self).
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
class
Goulib.table.Table(data=[], **kwargs)[source]¶ Bases:
listTable class with CSV I/O, easy access to columns, HTML output
inits a table, optionally by reading a Excel, csv or html file :param data: list of list of cells, or string as filename :param titles: optional list of strings used as column id :param footer: optional list of functions used as column reducers
-
__init__(data=[], **kwargs)[source]¶ inits a table, optionally by reading a Excel, csv or html file :param data: list of list of cells, or string as filename :param titles: optional list of strings used as column id :param footer: optional list of functions used as column reducers
-
html(head=None, foot=None, **kwargs)[source]¶ HTML representation of table
Parameters: - head – optional column headers, .titles by default
- foot – optional column footers, .footer by default
- style – style for the table
- colstyle – list of dict of style attributes for each column
- kwargs – optional parameters passed along to tag(‘table’… except: * start=optional start row * stop=optional end row used to display a subset of lines. in this case rows with ‘…’ cells are displayed before and/or after the lines
Returns: string HTML representation of table
-
read_element(element, **kwargs)[source]¶ read table from a DOM element. :Warning: drops all formatting
-
transpose(titles_column=0)[source]¶ transpose table :param: titles_column :return: Table where rows are made from self’s columns and vice-versa
-
setcol(col, value, i=0)[source]¶ set column values :param col: int or string column index :param value: single value assigned to whole column or iterable assigned to each cell :param i: optional int : index of first row to assign
-
append(line)[source]¶ appends a line to table :param line: can be either: * a list * a dict or column names:values
-
hierarchy(by='Level', factory=<function Table.<lambda>>, linkfct=<function Table.<lambda>>)[source]¶ builds a structure from a table containing a “level” column
-
applyf(by, f, skiperrors=False)[source]¶ apply a function to a column :param by: column name of number :param f: function of the form lambda cell:content :param skiperrors: bool. if True, errors while running f are ignored :return: bool True if ok, False if skiperrors==True and conversion failed
-
__add__¶ Return self+value.
-
__class__¶ alias of
builtins.type
-
__contains__¶ Return key in self.
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__iadd__¶ Implement self+=value.
-
__imul__¶ Implement self*=value.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__mul__¶ Return self*value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__reversed__()¶ Return a reverse iterator over the list.
-
__rmul__¶ Return value*self.
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__()¶ Return the size of the list in memory, in bytes.
-
clear()¶ Remove all items from list.
-
copy()¶ Return a shallow copy of the list.
-
count()¶ Return number of occurrences of value.
-
extend()¶ Extend list by appending elements from the iterable.
-
insert()¶ Insert object before index.
-
pop()¶ Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
-
remove()¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
reverse()¶ Reverse IN PLACE.
-