4.1. Data Structure

4.1.1. TableData

class tabledata.TableData(table_name: Optional[str], headers: Sequence[str], rows: Sequence[T_co], dp_extractor: Optional[dataproperty._extractor.DataPropertyExtractor] = None, type_hints: Optional[Sequence[Union[str, Type[typepy.type._base.AbstractType], None]]] = None, max_workers: Optional[int] = None, max_precision: Optional[int] = None)[source]

Class to represent a table data structure.

Parameters:
  • table_name – Name of the table.
  • headers – Table header names.
  • rows – Data of the table.
as_dataframe() → DataFrame[source]
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(default_key: str = 'table') → Dict[str, List[OrderedDict[str, Any]]][source]
Parameters:default_key – Key of a returning dictionary when the table_name is empty.
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() → Iterator[Tuple][source]
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: bool = True) → bool[source]
filter_column(patterns: Optional[str] = None, is_invert_match: bool = False, is_re_match: bool = False, pattern_match: tabledata._constant.PatternMatch = <PatternMatch.OR: 0>) → tabledata._core.TableData[source]
static from_dataframe(dataframe, table_name: str = '', type_hints: Optional[Sequence[Optional[Type[typepy.type._base.AbstractType]]]] = None, max_workers: Optional[int] = None) → tabledata._core.TableData[source]

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
headers

Get the table header names.

Returns:Table header names.
Return type:list or tuple
in_tabledata_list(other: Sequence[T_co], cmp_by_dp: bool = True) → bool[source]
is_empty() → bool[source]
Returns:True if the data headers or value_matrix is empty.
Return type:bool
is_empty_header() → bool[source]
Returns:True if the data headers is empty.
Return type:bool
is_empty_rows() → bool[source]
Returns:True if the tabular data has no rows.
Return type:bool
max_workers
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
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() → tabledata._core.TableData[source]
validate_rows() → None[source]
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