Search code examples
csvkdbq-lang

kdb+ How do I import only specific columns from a CSV file into a table


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?


Solution

  • 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