Save a result from table in a csv file for output

1,365 views
Skip to first unread message

minh

unread,
Sep 18, 2009, 6:24:16 AM9/18/09
to Kdb+ Personal Developers
Hi,
I want to Save a result from table in a csv file for output.
the name of my table is a simple table with date and px
when i save in the file res_ma.csv, I have the error `type
`:res_ma.csv 0: res_ma

Can somebody guide me how to save these data in a file?

Thanks a lot Minh
See below:

q)table
date px
----------------------
7/13/2009 17:00 98.81
7/13/2009 16:30 98.81
7/13/2009 16:00 98.805
....

q) px_series:select px from table
px
------
98.81
98.81
98.805
.....

q)res_ma:mavg[25;px_series]

q) `:res_ma.csv 0: res_ma
'type

Aaron Davies

unread,
Sep 18, 2009, 1:28:27 PM9/18/09
to personal...@googlegroups.com
> I want to Save a result from table in a csv file for output.

"save" will do this automagically

% q
KDB+ 2.6 2009.09.15 Copyright (C) 1993-2009 Kx Systems
m32/ 2()core 2048MB

q)t:([]a:1 2 3)
q)save`t.csv
`:t.csv
q)\\
% cat t.csv
a
1
2
3

Kurt Kretzer

unread,
Sep 18, 2009, 4:39:13 PM9/18/09
to Kdb+ Personal Developers
You can also use this method:

q)`:anyfilename.csv 0: "," 0: table

The first use of 0: (with the "," as the left arg) turns the table
into a list of csv strings, and then the second use of 0: writes the
csv strings to the file. The save command is easier, but the above
method a) lets you give the file any name you want, and b) will also
work on local table variables within a function (save only works for
global tables).

minh

unread,
Sep 18, 2009, 11:03:10 PM9/18/09
to Kdb+ Personal Developers
Hi Kurt, Aaron,

Thanks for your usefull feedbacks.
This works perfectly.
Have a great day
Minh
> > 3- Hide quoted text -
>
> - Show quoted text -

Tim Rieder

unread,
Sep 19, 2009, 10:57:09 AM9/19/09
to personal...@googlegroups.com
One thing to keep in mind is that nested character columns (strings)
are automatically escaped if they contain commas, but in the rare
event you have a symbol column with a comma, it will not be escaped.
To avoid problems convert sym columns to strings if you think they may
contain commas.


On Sep 18, 2009, at 4:39 PM, Kurt Kretzer <kurt.k...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages