如何解决在 q/kdb 中读取带有注释和空行的 csv 文件
我正在尝试读取带有注释和空行的 csv 文件,我需要从中获取非空或未注释的行。
文件看起来像这样:
试运行的测试文件:
#This is a comment
# This is a comment with,comma
# This,is,a,comment with exact number of commas as valid lines
h1,h2,h3,h4
a,b,c,d
e,f,g,h
i,j,k,l
m,n,o,p
预期输出:
h1 h2 h3 h4
-----------
a b c d
e f g h
i j k l
m n o p
尝试失败:
q)("SSSS";enlist ",")0: ssr[;;]each read0 `:test.csv // tried various options with ssr but since '*' wildcard gives error with ssr so not sure of how to use regex here
解决方法
这提供了所需的结果。
q)("SSSS";enlist",")0:t where not""~/:t:5_read0`:test.csv
h1 h2 h3 h4
-----------
a b c d
e f g h
i j k l
m n o p
忽略您可以使用的任意数量的评论。
q)("SSSS";enlist",")0:t where not any each(" ";"#")~\:/:first each t:read0`:test.csv
h1 h2 h3 h4
-----------
a b c d
e f g h
i j k l
m n o p
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。