csv.q
Read delimited text (CSV, TSV) as a table, from a file, a URL or text in memory. `select from `:trades.csv` is the shortest spelling; .csv.read adds a target table, explicit column types and options; .csv.info shows the schema it would sniff. What a cell means is shared with .j.read (user-docs/loading.md).
Examples
select from `:https://www.timestored.com/data/sample/dowjones.csv where Date>1960.01.01
select MIC, CITY from `:https://www.timestored.com/data/sample/iso10383_mic.csv where CITY like "LONDON"
`:trades.csv 0: csv 0: ([] sym:`a`b; px:1.5 2.5)
select from `:trades.csv where px>2
t:.csv.read[`:trades.csv;::;(enlist `sym)!enlist "s";()!()]Entity Summary
| Entities | Short Description |
|---|---|
| .csv.info[file;opts] | The schema .csv.read would infer, as the dict its types argument takes, without loading the file. |
| .csv.read[file;target;types;opts] | Load delimited text as a table. |
Entity Details
.csv.info[file;opts]
The schema .csv.read would infer, as the dict its types argument takes, without loading the file. Advisory "s" marks a low-cardinality text column .csv.read alone would keep as strings. Only the sniff sample is read.
| Return: | a dict of column name to type char |
|---|---|
| Parameters: |
|
Examples
.csv.info["a,b\n1,x\n";()!()].csv.read["a,b\n1,x\n";::;.csv.info["a,b\n1,x\n";()!()];()!()].csv.read[file;target;types;opts]
Load delimited text as a table. A symbol is a resource to open, text is the content itself. Types resolve as: explicit types > an existing target table's schema > the sniff, and are fixed after the sniff sample: a later cell that fails its type signals 'csv. Sniffed text is a string column; ask for symbols with types. The delimiter is sniffed among , ; tab |; quote, escape and comment are never sniffed.
| Parameters: |
|
|---|---|
| throws: |
Examples
.csv.read["sym,px\na,1.5\nb,2.5\n";::;(enlist `sym)!enlist "s";()!()].csv.read["h\nx\n1\n2\n";::;::;(enlist `skip)!enlist 1].csv.read["a\n1\n2\n";{[tblData;errData;misc] show count tblData};::;()!()]