Reading PyKX data from disk
pykx.read
QReader
QReader(q)
Read data using q.
csv
csv(path, types=None, delimiter=',', as_table=True)
Reads a CSV file as a table or dictionary.
Column types are guessed if not provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path, k.SymbolAtom]
|
The path to the CSV file. |
required |
types |
Optional[Union[bytes, k.CharAtom, k.CharVector]]
|
Can be a dictionary of columns and their types or a |
None
|
delimiter |
Union[str, bytes, k.CharAtom]
|
A single character representing the delimiter between values. |
','
|
as_table |
Union[bool, k.BooleanAtom]
|
|
True
|
Returns:
Type | Description |
---|---|
Union[k.Table, k.Dictionary]
|
The CSV data as a |
See Also
Examples:
Read a comma seperated CSV file into a pykx.Table
guessing the datatypes of each
column.
table = q.read.csv('example.csv')
Read a tab seperated CSV file into a pykx.Table
while specifying the columns
datatypes to be a pykx.SymbolVector
followed by two pykx.LongVector
columns.
table = q.read.csv('example.csv', 'SJJ', ' ')
Read a comma seperated CSV file into a pykx.Dictionary
, guessing the datatypes of
each column.
table = q.read.csv('example.csv', None, None, False)
Read a comma separated CSV file specifying the type of the three columns
named x1
, x2
and x3
to be of type Integer
, GUID
and Timestamp
.
table = q.read.csv('example.csv', {'x1':kx.IntAtom,'x2':kx.GUIDAtom,'x3':kx.TimestampAtom})
splayed
splayed(root, name)
Loads a splayed table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
Union[str, Path, k.SymbolAtom]
|
The path to the root directory of the splayed table. |
required |
name |
Union[str, k.SymbolAtom]
|
The name of the table to read. |
required |
Returns:
Type | Description |
---|---|
k.SplayedTable
|
The splayed table as a |
See Also
Examples:
Reads a splayed table named t
found within the current directory
table = q.read.splayed('.', 't')
Reads a splayed table named splayed
found within the /tmp
directory
table = q.read.splayed('/tmp', 'splayed')
fixed
fixed(path, types, widths)
Loads a file of typed data with fixed-width fields.
It is expected that there will either be a newline after every record, or none at all.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path, k.SymbolAtom]
|
The path to the file containing the fixed-width field data. |
required |
types |
Union[bytes, k.CharVector]
|
A string of uppercase characters representing the types. Space is used to drop a column. |
required |
widths |
Union[List[int], k.LongVector]
|
The width in bytes of each field. |
required |
Returns:
Type | Description |
---|---|
k.List
|
The data as a |
Examples:
Read a file of fixed width data into a pykx.List
of two pykx.LongVectors
the first
with a size of 1 character and the second with a size of 2 characters.
data = q.read.fixed('example_file', [b'J', b'J'], [1, 2])
json
json(path)
Reads a JSON file into a k.Table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path, k.SymbolAtom]
|
The path to the JSON file. |
required |
Returns:
Type | Description |
---|---|
JSONKTypes
|
The JSON data as a |
See Also
Examples:
Read a JSON file.
data = q.read.json('example.json')
serialized
serialized(path)
Reads a binary file containing serialized q data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path, k.SymbolAtom]
|
The path to the q data file. |
required |
Returns:
Type | Description |
---|---|
k.K
|
The q data file converted to a |
See Also
Examples:
Read a q data file containing a serialized table into a pykx.Table
object.
table = q.read.serialized('q_table_file')