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:
object
Table 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()
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
() → list¶ 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).
-
__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
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
class
Goulib.table.
Row
(data, align=None, fmt=None, tag=None, style={})[source]¶ Bases:
object
Table 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
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
() → list¶ 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).
-
__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
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
class
Goulib.table.
Table
(data=[], **kwargs)[source]¶ Bases:
list
Table 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, colstyle={}, **kwargs)[source]¶ HTML representation of table
Parameters: - head – optional column headers, .titles by default
- foot – optional column footers, .footer by default
- style – (list of) dict of style attributes
- 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
-
__add__
¶ Return self+value.
-
__contains__
¶ Return key in self.
-
__delattr__
¶ Implement delattr(self, name).
-
__delitem__
¶ Delete self[key].
-
__dir__
() → list¶ 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.
-
__iter__
¶ Implement iter(self).
-
__le__
¶ Return self<=value.
-
__len__
¶ Return len(self).
-
__lt__
¶ Return self<value.
-
__mul__
¶ Return self*value.n
-
__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__
()¶ L.__reversed__() – return a reverse iterator over the list
-
__rmul__
¶ Return self*value.
-
__setattr__
¶ Implement setattr(self, name, value).
-
__setitem__
¶ Set self[key] to value.
-
__sizeof__
()¶ L.__sizeof__() – size of L in memory, in bytes
-
append
(line)[source]¶ appends a line to table :param line: can be either: * a list * a dict or column names:values
-
clear
() → None -- remove all items from L¶
-
copy
() → list -- a shallow copy of L¶
-
count
(value) → integer -- return number of occurrences of value¶
-
extend
(iterable) → None -- extend list by appending elements from the iterable¶
-
insert
()¶ L.insert(index, object) – insert object before index
-
pop
([index]) → item -- remove and return item at index (default last).¶ Raises IndexError if list is empty or index is out of range.
-
remove
(value) → None -- remove first occurrence of value.¶ Raises ValueError if the value is not present.
-
reverse
()¶ L.reverse() – reverse IN PLACE
-
hierarchy
(by='Level', factory=<function Table.<lambda>>, linkfct=<function Table.<lambda>>)[source]¶ builds a structure from a table containing a “level” column
-