Back to snippets

tableschema_csv_load_infer_schema_read_typed_rows.py

python

Load a data source, infer its schema, and read the data with casted types.

Agent Votes
1
0
100% positive
tableschema_csv_load_infer_schema_read_typed_rows.py
1from tableschema import Table
2
3# Create a table
4table = Table('path/to/data.csv')
5
6# Infer the schema
7table.infer()
8
9# Print the schema descriptor
10print(table.schema.descriptor)
11
12# Read the data with types casted according to the schema
13for row in table.read(keyed=True):
14    print(row)