KDB-如何选择具有前缀数字的列?

发布于 2025-01-18 06:48:59 字数 704 浏览 2 评论 0原文

我有一个试图关闭的属性表,虽然枢轴是有道理的,但我成功旋转的几个关键属性值均以数字(用于排序目的)的前缀。这些是我们要旋转并报告的重要属性(有几个)。

我在这里找到了一个类似的问题:如何如何 对字典.q.id t进行消毒时

要在kdb中选择包含列名中的dot的列,然后当我 在返回的值中,它返回99H,因此枢轴返回字典。

我正在尝试利用entrist(`1代码)#T,但尚无可用。

有什么想法或建议吗?

q) t

monthDate | 1CODE    2CODE     3CODE    4CODE    
----------| ------------------------------------
2022.01.01| 18.0054  0.1537228 4.116678 9.332936
2022.02.01| 17.87151 0.1527959 3.866393 9.685012
2022.03.01| 17.739   0.1518747 3.646734 10.00515
...

I have a table of attributes that I am trying to pivot off of and while the pivot makes sense, several key attribute values I am successfully pivoting off of are prefixed with numbers (for sorting purposes). These are important attributes (there are several like this) that we want to pivot and report on.

I found a similar question here: How to select a column containing dot in column name in kdb and am when I sanitize the dictionary .Q.id t prefixed the columns with a

When I ran type on the returned value it returned 99h so the pivot returns a dictionary.

I'm trying to leverage enlist(`1CODE)#t but to no avail as of yet.

Any thoughts or suggestions?

q) t

monthDate | 1CODE    2CODE     3CODE    4CODE    
----------| ------------------------------------
2022.01.01| 18.0054  0.1537228 4.116678 9.332936
2022.02.01| 17.87151 0.1527959 3.866393 9.685012
2022.03.01| 17.739   0.1518747 3.646734 10.00515
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

○愚か者の日 2025-01-25 06:48:59

您不能在键控表上使用 colName#table99h 在本例中是键控表,尽管键控表也是字典)。因此,您必须首先使用 0! 取消表的密钥

t:1!flip`monthDate`1CODE`2CODE!(2022.01.01 2022.02.01 2022.03.01;3?100.;3?10.);

q)((),`1CODE)#0!t
1CODE
--------
61.37452
52.94808
69.16099

q)((),`1CODE`2CODE)#0!t
1CODE    2CODE
------------------
61.37452 0.8388858
52.94808 1.959907
69.16099 3.75638

You can't use colName#table on a keyed table (99h is a keyed table in this case, though yes a keyed table is also a dictionary). So you would have to unkey the table first using 0!

t:1!flip`monthDate`1CODE`2CODE!(2022.01.01 2022.02.01 2022.03.01;3?100.;3?10.);

q)((),`1CODE)#0!t
1CODE
--------
61.37452
52.94808
69.16099

q)((),`1CODE`2CODE)#0!t
1CODE    2CODE
------------------
61.37452 0.8388858
52.94808 1.959907
69.16099 3.75638
り繁华旳梦境 2025-01-25 06:48:59

kdb 中的表只是字典列表。 99h 类型既可以是键控表,也可以是字典。如果您已经清理了表,您仍然可以使用 qsql:

q)select a1CODE from .Q.id t
a1CODE
--------
18.0054
17.87151
17.739

另一个选择是使用 xcol 重命名您的列:

q)t:(`monthDate,`$1 rotate'string 1_cols t)xcol t
q)select CODE1 from t1
CODE1
--------
47.35547
75.21426
99.14374

Tables in kdb are just lists of dictionaries. Type 99h can be both a keyed table and a dictionary. You can still use qsql if you've sanitised your table:

q)select a1CODE from .Q.id t
a1CODE
--------
18.0054
17.87151
17.739

Another option is to use xcol to rename your columns:

q)t:(`monthDate,`$1 rotate'string 1_cols t)xcol t
q)select CODE1 from t1
CODE1
--------
47.35547
75.21426
99.14374
茶花眉 2025-01-25 06:48:59

我不确定你一开始所说的旋转是什么意思,但对我来说突出的一个问题是 enlist 函数应该使用方括号 - 而不是你帖子中的圆括号。所以你想要的代码是:

  enlist[`1CODE]#t 

I'm not sure what you mean by pivoting off of at the beginning, but an issue that sticks out to me is that the enlist function should use square brackets - rather than the round ones in in your post. So the code you want is:

  enlist[`1CODE]#t 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文