-
Exporting CSV file
Posted by aakash on July 24, 2023 at 12:00 amI 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
aakash replied 8 months, 1 week ago 2 Members · 4 Replies -
4 Replies
-
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?
-
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?
Log in to reply.