KDB-如何选择具有前缀数字的列?
我有一个试图关闭的属性表,虽然枢轴是有道理的,但我成功旋转的几个关键属性值均以数字(用于排序目的)的前缀。这些是我们要旋转并报告的重要属性(有几个)。
我在这里找到了一个类似的问题:如何如何 对字典.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能在键控表上使用
colName#table
(99h
在本例中是键控表,尽管键控表也是字典)。因此,您必须首先使用0!
取消表的密钥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 using0!
kdb 中的表只是字典列表。 99h 类型既可以是键控表,也可以是字典。如果您已经清理了表,您仍然可以使用 qsql:
另一个选择是使用 xcol 重命名您的列:
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:
Another option is to use xcol to rename your columns:
我不确定你一开始所说的旋转是什么意思,但对我来说突出的一个问题是 enlist 函数应该使用方括号 - 而不是你帖子中的圆括号。所以你想要的代码是:
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: