1

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 1

3

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
Sign up to request clarification or add additional context in comments.

5 Comments

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.
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.csv
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.
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 here
thanks James yet again, thats what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.