英文:
create new cols based on a delimiter from a particular column
问题
我有一个名为tab的表,其中有多个列。我对类型为C的列text感兴趣。
现在我们想要使用文本列并基于分隔符; 进行拆分并创建一个新列。
所以这里列名将是rank,它的值将是1等等...
在kdb+中我们如何做到这一点?
我之前想出了以下方法,但我不想使用它,因为它将硬编码到项目6等等...如果顺序改变了怎么办,或者如果国家丢失了,那么它将会出现问题。
res:update `$(raze(" *";"=")0:string country) from update country:(`$";" vs' text)[;6] from res;
英文:
I have a table say tab where there are multiple cols. I am interested to in the column text which is of type C.
Now we want to use text column and split based on delimeter ; and create a new column
So here column name will be rank and its value will be 1 and so on...
How do we that in kdb+?
I had came up with below but i dont want to use it as its hardcoded it to item 6 and so on.. what if the order changes, or if country is missing, then it'll break
res:update `$(raze(" *";"=")0:string country) from update country:(`$";" vs' text)[;6] from res;
答案1
得分: 5
以下是您要翻译的内容:
"PLEASE provide sample code to create your data when asking a question, a picture doesn't help us."
这是相关文档的部分链接:https://code.kx.com/q/ref/file-text/#key-value-pairs
英文:
PLEASE provide sample code to create your data when asking a question, a picture doesn't help us.
q)t:([]text:("aa=1;bb=XYZ;cc=$1.23";"bb=TUV;dd=3.4%";"aa=foo;cc=10"))
q)t,'(uj/)exec{enlist(!/)"S=;"0:x}'[text]from t
text aa bb cc dd
-------------------------------------------------
"aa=1;bb=XYZ;cc=$1.23" ,"1" "XYZ" "$1.23" ""
"bb=TUV;dd=3.4%" "" "TUV" "" "3.4%"
"aa=foo;cc=10" "foo" "" "10" ""
This is the relevant part of the documentation: https://code.kx.com/q/ref/file-text/#key-value-pairs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论