4.1. Data Structure

4.1.1. TableData

class tabledata.TableData(table_name, headers, rows, dp_extractor=None, type_hints=None)

Class to represent a table data structure.

Parameters:
  • table_name (str) – Name of the table.
  • headers (list) – Table header names.
  • rows (list) – Data of the table.
as_dataframe()
Returns:

Table data as a pandas.DataFrame instance.

Return type:

pandas.DataFrame

Sample Code:
from tabledata import TableData

TableData(
    "sample",
    ["a", "b"],
    [[1, 2], [3.3, 4.4]]
).as_dataframe()
Output:
     a    b
0    1    2
1  3.3  4.4
Dependency Packages:
 
as_dict()
Returns:

Table data as a dict instance.

Return type:

dict

Sample Code:
from tabledata import TableData

TableData(
    "sample",
    ["a", "b"],
    [[1, 2], [3.3, 4.4]]
).as_dict()
Output:
{'sample': [OrderedDict([('a', 1), ('b', 2)]), OrderedDict([('a', 3.3), ('b', 4.4)])]}
as_tuple()
Returns:

Rows of the table.

Return type:

list of namedtuple

Sample Code:
from tabledata import TableData

records = TableData(
    "sample",
    ["a", "b"],
    [[1, 2], [3.3, 4.4]]
).as_tuple()
for record in records:
    print(record)
Output:
Row(a=1, b=2)
Row(a=Decimal('3.3'), b=Decimal('4.4'))
column_dp_list
dp_extractor
equals(other, cmp_by_dp=False)
filter_column(patterns=None, is_invert_match=False, is_re_match=False, pattern_match=<PatternMatch.OR: 0>)
static from_dataframe(dataframe, table_name=u'')

Initialize TableData instance from a pandas.DataFrame instance.

Parameters:
  • dataframe (pandas.DataFrame) –
  • table_name (str) – Table name to create.
has_value_dp_matrix
header_dp_list
header_list
headers

Get the table header names.

Returns:Table header names.
Return type:list or tuple
in_tabledata_list(other, cmp_by_dp=False)
is_empty()
Returns:True if the data headers or value_matrix is empty.
Return type:bool
is_empty_header()
Returns:True if the data headers is empty.
Return type:bool
is_empty_record()
is_empty_rows()
Returns:True if the tabular data has no rows.
Return type:bool
num_columns
num_rows
Number of rows in the tabular data. None if the rows is neither list nor tuple.
Return type:int
Type:return
row_list
rows

Original rows of tabular data.

Returns:Table rows.
Return type:list or tuple
table_name

Name of the table. :rtype: str

Type:return
transpose()
validate_rows()
Raises:ValueError
value_dp_matrix

DataProperty for table data. :rtype: list

Type:return
value_matrix

Converted rows of tabular data.

Returns:Table rows.
Return type:list or tuple