The Tab class supports importing and exporting of tabular data from various sources. Import is achieved through the load() function, export through the table’s Tab.save() method.
Example:
# load data from comma separated value file using ',' as the separator
tab = tap.load('data.csv', sep=',')
Load table from an input stream or the file pointed to by filename.
By default, the file format is set to auto, which tries to guess the file format from the file extension. The following file extensions are recognized:
extension | recognized format |
---|---|
.csv | comma separated values |
.pickle | pickled byte stream |
<all others> | ost-specific format |
For csv and pickle files with other file extensions, the format must be specified explicitly by setting format the appropriate format string.
The following file formats are understood:
ost
This is an ost-specific, but still human readable file format. The file (stream) must start with header line of the form
col_name1[type1] <col_name2[type2]>...
The types given in brackets must be one of the data types the Tab class understands. Each following line in the file then must contains exactly the same number of data items as listed in the header. The data items are automatically converted to the column format. Lines starting with a ‘#’ and empty lines are ignored.
pickle
Deserializes the table from a pickled byte stream
csv
Reads the table from comma separated values stream. Since there is no explicit type information in the csv file, the column types are guessed, using the following simple rules:
Returns: | A new Tab instance |
---|
save the table to stream or file pointed to by filename. The following three file formats are supported (for more information on file formats, see load()):
ost | ost-specific format (human readable) |
csv | comma separated values (human readable) |
pickle | pickled byte stream (binary) |
html | HTML table |
context | ConTeXt table |
Parameters: |
|
---|---|
Raises : | ValueError if format is unknown |