Exporting CSV file

https://learninghub.kx.com/forums/topic/exporting-csv-file

I want to export a CSV from kdb.
i want to add a tab with each column. How can i achieve that?

 

data: enlist"n"sv ","0:rows

 

 

Note, this was just a quick attempt:

q)testfile:flip {(1#x),"t",'/:1_x} csv vs' csv 0: t save `:testfile.csv

 

Hi ,

Your question isn’t very clear. Do you want to export a table to a csv, or a table with column headers that include tabs?

Have a look at Handling CSVs in kdb+ | A tour of the q programming language | Documentation for kdb+ and the q programming language - Kdb+ and q documentation (kx.com)

Hi
I want to export a table to a csv, where each new rows with type string needs to have tabs under each column.

I’m not following your request. I read it as follows, which I don’t think is what you mean?

 

q)t:([]c1:`a`b`c;c2:1 2 3) 
q){cc:count cols t;x:csv 0: x;(1#x),enlist[(csv sv cc# enlist enlist "t")],1_x} 
t "c1,c2" "t,t" "a,1" "b,2" "c,3" 

q)(count[cols t]#"*";enlist csv) 0: {cc:count cols t;x:csv 0: x;(1#x),enlist[(csv sv cc# enlist enlist "t")],1_x} 
t c1 c2 
----------- 
,"t" ,"t" ,"a" ,"1" ,"b" ,"2" ,"c" ,"3"

 

If you prepare you csv data and read from disk, you’ll recreate a table without needing to add tabs:

 

q)csv 0: t “c1,c2” “a,1” “b,2” “c,3” q)(count[cols t]#“*”;enlist csv) 0: csv 0: t c1 c2 --------- ,“a” ,“1” ,“b” ,“2” ,“c” ,“3”

 

Can you provide a before and after example of what you mean?