ColumnKeyExistsQ[data,key]
ColumnKeyExistsQ[key]
表示可应用于表达式的 ColumnKeyExistsQ 的算符形式.
ColumnKeyExistsQ
ColumnKeyExistsQ[data,key]
ColumnKeyExistsQ[key]
表示可应用于表达式的 ColumnKeyExistsQ 的算符形式.
更多信息
- ColumnKeyExistsQ 通常用于在使用某个列键之前,确认该列键是否存在.
- ColumnKeyExistsQ[data,key] 中 data 可采用的形式包括:
-
Tabular[…] 表格数据,由各种类型的列组成 Dataset[…] 普通分层数据 {assoc1,assoc2,…} 含有有公共键的关联列表 TimeSeries[…] 含有多个分量的时间序列 EventSeries[…] 含有多个分量的事件序列 - ColumnKeyExistsQ[key][data] 等价于 ColumnKeyExistsQ[data,key].
范例
打开所有单元 关闭所有单元基本范例 (1)
查看列的键是否存在于 Tabular 对象中:
Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}]ColumnKeyExistsQ[%, "b"]ColumnKeyExistsQ[%%, "d"]范围 (8)
数据形式 (6)
查看列的键是否出现在 Tabular 对象中:
tab = Tabular[{{1.2, "a", True}, {-3.5, "f", False}}, {"col1", "col2", "col3"}]ColumnKeyExistsQ[tab, "col3"]ColumnKeyExistsQ[tab, "col"]对于没有列的键的 Tabular 对象,ColumnKeyExistsQ 总是返回 False:
tab = Tabular[{{1, 2, 3}, {4, 5, 6}}]ColumnKeyExistsQ[tab, 2]ColumnKeyExistsQ[tab, "2"]ColumnKeyExistsQ[tab, "Column2"]assocs = {<|"a" -> 1, "b" -> 1.5|>, <|"a" -> 2, "c" -> 3.5|>};ColumnKeyExistsQ[assocs, "a"]ColumnKeyExistsQ[assocs, "b"]ColumnKeyExistsQ[assocs, "c"]ColumnKeyExistsQ[assocs, "d"]ColumnKeyExistsQ 实际上会假设使用 Missing[…] 值,和 Tabular 一样:
Tabular[assocs]查看列的键是否出现在 Dataset 对象中:
ds = Dataset[{<|"a" -> 1, "b" -> True|>, <|"a" -> 3, "b" -> False|>}]ColumnKeyExistsQ[ds, "b"]ColumnKeyExistsQ[ds, "c"]检查 EventSeries 对象中某个键是否存在:
EventSeries[{{1, "dog"}, {2, "cat"}, {4, "fox"}}, {{0, 0.1, 0.5}}, ComponentKeys -> {"number", "animal"}]ColumnKeyExistsQ[%, "animal"]ColumnKeyExistsQ[%%, "foo"]使用 ColumnKeyExistsQ 的算符形式:
Tabular[{{1.2, "a"}, {-3.5, "f"}}, {"col1", "col2"}]%//ColumnKeyExistsQ["col2"]%%//ColumnKeyExistsQ["COL2"]键的形式 (2)
查看给定的列的键是否出现在 Tabular 对象中:
tab = Tabular[{{1, "a", True}, {2, "b", False}}, {"col1", "col2", "col3"}]ColumnKeyExistsQ[tab, "col2"]ColumnKeyExistsQ[tab,key] 中的键可被封装在 Key 或 ExtendedKey 中:
ColumnKeyExistsQ[tab, Key["col2"]]ColumnKeyExistsQ[tab, ExtendedKey["col2"]]取一个含有扩展键的 Tabular 对象:
tab = Tabular[{{1, "a", 3.2}, {2, "b", 7.5}}, {ExtendedKey["col1", "number"], ExtendedKey["col1", "string"], ExtendedKey["col2", "number"]}]ColumnKeyExistsQ[tab, ExtendedKey["col1", "string"]]ColumnKeyExistsQ[tab, ExtendedKey["col2", "string"]]ColumnKeyExistsQ[tab, "string"]ColumnKeyExistsQ[tab, "number"]属性和关系 (2)
ColumnKeyExistsQ[tab,key] 等价于 MemberQ[ColumnKeys[tab],key]:
tab = Tabular[{{1, "a", True}, {2, "b", False}}, {"col1", "col2", "col3"}]{ColumnKeyExistsQ[tab, "col2"], ColumnKeyExistsQ[tab, "col4"]}keys = ColumnKeys[tab]{MemberQ[keys, "col2"], MemberQ[keys, "col4"]}对于关联 assocs 的列表,ColumnKeyExistsQ[assocs,key] 相当于在关联中使用 KeyExistsQ:
assocs = {<|"a" -> 1, "b" -> True|>, <|"a" -> 4, "c" -> Today|>}ColumnKeyExistsQ["a"]@assocsKeyExistsQ["a"] /@ assocs如果该键存在于任何关联中,ColumnKeyExistsQ 返回 True:
ColumnKeyExistsQ["b"]@assocsKeyExistsQ["b"] /@ assocs相关指南
-
▪
- 表格对象
文本
Wolfram Research (2025),ColumnKeyExistsQ,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ColumnKeyExistsQ.html (更新于 2026 年).
CMS
Wolfram 语言. 2025. "ColumnKeyExistsQ." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2026. https://reference.wolfram.com/language/ref/ColumnKeyExistsQ.html.
APA
Wolfram 语言. (2025). ColumnKeyExistsQ. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ColumnKeyExistsQ.html 年
BibTeX
@misc{reference.wolfram_2026_columnkeyexistsq, author="Wolfram Research", title="{ColumnKeyExistsQ}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/ColumnKeyExistsQ.html}", note=[Accessed: 15-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_columnkeyexistsq, organization={Wolfram Research}, title={ColumnKeyExistsQ}, year={2026}, url={https://reference.wolfram.com/language/ref/ColumnKeyExistsQ.html}, note=[Accessed: 15-September-2026]}