Edit page in Livemark
(2024-12-13 12:49)

Table Resource

A table resource contains a tabular data file (can be validated with Table Schema):

from frictionless.resources import TableResource

resource = TableResource(path='table.csv')
resource.infer(stats=True)
print(resource)
{'name': 'table',
 'type': 'table',
 'path': 'table.csv',
 'scheme': 'file',
 'format': 'csv',
 'mediatype': 'text/csv',
 'encoding': 'utf-8',
 'hash': 'sha256:a1fd6c5ff3494f697874deeb07f69f8667e903dd94a7bc062dd57550cea26da8',
 'bytes': 30,
 'fields': 2,
 'rows': 2,
 'schema': {'fields': [{'name': 'id', 'type': 'integer'},
                       {'name': 'name', 'type': 'string'}]}}

We can read the contents:

from frictionless.resources import TableResource

resource = TableResource(path='table.csv')
resource.infer(stats=True)
print(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]