FuzzyTable

class fuzzytable.FuzzyTable(path: Union[str, pathlib.Path], sheetname: Optional[str] = None, fields: Union[Iterable[str], Iterable[fuzzytable.patterns.fieldpattern.FieldPattern], str, fuzzytable.patterns.fieldpattern.FieldPattern, None] = None, header_row: Optional[int] = None, header_row_seek: Union[bool, int] = False, name: Optional[str] = None, approximate_match=False, min_ratio=sentinel.DefaultValue, missingfieldserror_active=False, mode=sentinel.DefaultValue, case_sensitive=sentinel.DefaultValue)

Extract a table from a spreadsheet.

This is the main class of fuzzytable. Instantiate it to extract the data. Then interact with the extracted table in one of four ways:

Methods

items() Like dict.items().
keys() Like dict.keys().
values() Like dict.values().

See learn_fuzzytable:

Parameters:
  • path (path-like str, pathlib.Path object) – Must be a valid csv or excel file.
  • sheetname (str, default None) – Must be supplied if path is an excel file.
  • header_row (int >=1, default None) –

    Row number m where FuzzyTable expects the headers to be.

    • None: m = 1
    • int: m = header_row
  • header_row_seek (bool, int >= 1, default False) –

    If Truthy: ignore header_row. Instead, FuzzyTable seeks the best fit header row within the first n rows.

    • int: n = header_row_seek
    • other truthy value: n = 20
  • fields (str or iterable thereof, default None) –
    • None: extract field_names for each non-None cell in header row.
    • str or iterable thereof: extract matching field_names matching a cell in the header row.
  • approximate_match (bool, default False) – If True, subfields will match if they are at least 60% similar to the field names supplied. This cutout value can be set with min_ratio. Deprecated in v0.18. To be removed in v1.0. Use mode instead.
  • min_ratio (float, default None) – The minimum similarity threshold for matching headers. Must be float 0.0 < x <= 1.0
  • name (str, default None) – Give this FuzzyTable instance a name.
  • mode (None or str) – Choose from 'exact', 'approx', or 'contains'. mode overrides approximate_match and contains_match.
  • case_sensitive (None or bool, default True) – Used when seeking header row and matching Fields to FieldPatterns.
records

Return Records object, a generator yielding records (rows), each represented as a dictionary.

fields

Return list of SingleField objects, with such attributes as name, header, data, col_num.

sheet

Return Sheet object, whose attributes store additional metadata about the worksheet.

Raises:fuzzytable.exceptions.FuzzyTableError – This is the module base exception. It is never itself raised, but you can use it to catch all exceptions raised by the FuzzyTable class. See Exceptions for all other exceptions raised by FuzzyTable.
items()

Like dict.items(). Return a generator yielding field name / column data tuples.

keys()

Like dict.keys(). Return a generator yielding field names.

values()

Like dict.values(). Return a generator yielding column data.