仅选择表中的那些列在q kdb中不具有空值

Uts*_*Uts 3 kdb

我有一张桌子:

q)t:([] a:1 2 3; b:```; c:`a`b`c)
a b c
-----
1   a
2   b
3   c
Run Code Online (Sandbox Code Playgroud)

从此表中,我只想选择不具有空值的列,在这种情况下,输出中应该省略列b(类似于pandas中的dropna方法)。

expected output
a c
---
1 a
2 b
3 c
Run Code Online (Sandbox Code Playgroud)

我尝试了很多类似的事情

select from t where not null cols
Run Code Online (Sandbox Code Playgroud)

但没有用。

小智 6

这是一个简单的解决方案,可以满足您的需求:

q)where[all null t]_t
a c
---
1 a
2 b
3 c
Run Code Online (Sandbox Code Playgroud)

[all null t]给出一个字典,该字典检查列值是否全部为null。

q)all null t
a| 0
b| 1
c| 0
Run Code Online (Sandbox Code Playgroud)

Where返回字典中的键,如果它是true

q)where[all null t]
,`b
Run Code Online (Sandbox Code Playgroud)

最后,您使用_从表t中删除列

希望这会有所帮助