1

I have a csv "pf.csv":

Jules,Winnfield  
Vincent,Vega  
Mia,Wallace  
Marsellus,Wallace  

And would like to specify a list of symbols which become the header when I read the csv. Normally I would load the csv like so:

("SS";enlist ",") 0: `$"pf.csv"

but that actually sets the first row as the keys in the flipped dictionary (i.e. the header in the table)
In the documentation for 0: I read

Optionally, 0: can take a three-item list as its second argument, containing the file handle, an offset at which to begin reading, and a length to read.

But that's inconvenient as the offset has to be given in number of characters and not in lines.

2 Answers 2

2

The way to go about this is to specify the column names before the bit you use to load the csv.

flip`fname`surname!("SS";",")0:`:pf.csv

You will also have to drop enlist because you do not have any column headers in your csv.

Another option would be to name the columns inside your *.csv file and then you can simply use enlist in your query to specify that the first row contains the column names.

Some more details here:

http://code.kx.com/q4m3/11_IO/#1152-variable-length-records https://code.kx.com/wiki/Reference/ZeroColon#Load_Delimited_Records_.28Read_CSV.29

Sign up to request clarification or add additional context in comments.

Comments

1

Could you try

flip `firstName`lastName!("SS";",") 0: `$"pf.csv"

Comments

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.