using csvutil.q to read in csv file

170 views
Skip to first unread message

Sam

unread,
Jan 27, 2013, 7:42:28 PM1/27/13
to personal...@googlegroups.com
Hi,

I am using csvutil.q (http://kx.com/q/e/csvutil.q) to parse csv files but having some trouble with boolean values.
e.g.
fname:`:test.csv;
info:.csv.info[fname];
info[`t]:"FSB";
rawtab:.csv.data[fname;info];

//test.csv
1.5,A,False
4.5,B,True

The problem I'm having is with boolean type (B). The boolean values in my csv file are either "false" or "true", and they are not parsed correctly such that all of them are set to 0 in rawtab. How do I change this csvutil.q file to make it parse this boolean values correctly? I tried some things but didn't work. Any help appreciated

thanks

Jack Andrews

unread,
Jan 27, 2013, 7:54:53 PM1/27/13
to personal...@googlegroups.com
you can read the values as syms and then update.

q)rawtab:([]n:1 2 3; s:`False`True`False)
q)update b:s=`True from `rawtab
`rawtab
q)show rawtab
n s b
---------
1 False 0
2 True 1
3 False 0

it might be best to avoid altering csvutil.q
> --
> You received this message because you are subscribed to the Google Groups
> "Kdb+ Personal Developers" group.
> To post to this group, send email to personal...@googlegroups.com.
> To unsubscribe from this group, send email to
> personal-kdbpl...@googlegroups.com.
> Visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Sam

unread,
Jan 27, 2013, 9:47:07 PM1/27/13
to personal...@googlegroups.com, ja...@ivorykite.com
Problem is that although this example is simple, in my table there are close to 50 columns and 15 boolean columns, so doing it this way is cumbersome. I've to change the parser to get this done efficiently.

Sam

unread,
Jan 29, 2013, 10:38:29 PM1/29/13
to personal...@googlegroups.com, ja...@ivorykite.com
Finally was able to revise the parser to recognize "True" and "False". thanks
Reply all
Reply to author
Forward
0 new messages