Example: CSV file with 4 headers: a,b,c,d. How do I only "pick" columns b & d for example, so I end up with a q table with two columns with the b & d headers?
1 Answer
For columns that you want to skip, use the space character in the "types" string. So to pick 'b' and 'd' columns:
q)\cat test.csv
"a,b,c,d"
"1,blah,3,4"
q)
q)(" S J";enlist csv) 0: `:test.csv
b d
------
blah 4
5 Comments
Alim Hasanov
Follow up question: I guess there is no way to actually use the name of the header to pick up the column? If I have 100s of columns and only wanted to use the actual header name as a string to pick up the given column. Unless I write up a sep function to parse the first header row and get the index of the desired column header.
James Little
Might not be the most efficient solution, but you could load all the data and then select the columns you need, e.g.
select b,d from ("****";enlist csv) 0: `:test.csvAlim Hasanov
Thank you . One last question. How do I import ALL the columns as strings, without having to type each column type as ("SSSSSS...") I want to onlu do something like ("all columns data type";enlist csv). Don't want to have to type each columns data type.
James Little
If you know how many columns are in the table (or count them beforehand), just use take
#, e.g. (4#"*";enlist csv) 0: `:test.csv. You should be wary of loading all strings as symbols though, unless they are repeating strings. See more hereAlim Hasanov
thanks James yet again, thats what I was looking for