创建新的列,基于特定列中的分隔符。

huangapple go评论92阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月31日 23:24:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定