RowKey
范例
打开所有单元 关闭所有单元基本范例 (2)
创建有三个列的 Tabular 对象:
Tabular[{{1, "a", 2.}, {4, "b", 3.}}, {"col1", "col2", "col3"}]tab = Tabular[%, <|"KeyColumns" -> {"col2"}|>]tab[RowKey[{"b"}]]%//Normal使用 RowKey[…] 作为函数,从带有键列的 Tabular 对象中提取一行:
EntityValue[{Entity["Country", "France"], Entity["Country", "Italy"]}, {"GDP", "Area"}, "Tabular"]%//RowKey[Entity["Country", "France"]]// Normal范围 (3)
创建含有关键列的 Tabular 对象:
tab = Tabular[{{"a", 2.}, {"b", 3.}}, <|"ColumnKeys" -> {"col1", "col2"}, "KeyColumns" -> {"col1"}|>]tab[RowKey[{"a"}]]%//Normal当只有一个关键列时,不需要 List 封装:
tab[RowKey["a"]]将 RowKey[…] 用作函数,应用到 Tabular 对象:
RowKey[{"b"}][Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["col1" -> Association["ElementType" -> "String"],
"col2" -> Association["ElementType" -> "Real64"]], "KeyColumns" -> {"col1"},
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{3, {0, 1, 2}, "ab"}, {}, None},
"ElementType" -> "String"]], TabularColumn[Association["Data" -> {{2., 3.}, {}, None},
"ElementType" -> "Real64"]]}}]]]]]获取一个含有 G7 国家人口的 Tabular 对象:
tab = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Year" -> Association["ElementType" -> "Integer64"],
"Country" -> Association["ElementType" -> "String"], "Population" ->
Association["ElementType" -> TypeSpecifier["Quantity"]["Real64", "People"]]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"],
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{1950, 1950, 1950, 1950, 1950, 1950, 1950, 2000, 2000,
2000, 2000, 2000, 2000, 2000}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{3, {0, 6, 12, 19, 24, 29, 42, 54, 60, 66, 73, 78, 83,
96, 108}, "CanadaFranceGermanyItalyJapanUnitedKingdomUnitedStatesCanadaFranceGermanyI\
talyJapanUnitedKingdomUnitedStates"}, {}, None}, "ElementType" -> "String"]],
TabularColumn[Association["Data" -> {14, {{{1.3737*^7, 4.1828673*^7, 6.8377*^7, 4.7104*^7,
8.31996*^7, 5.0127*^7, 1.513258*^8, 3.0529607*^7, 5.8494936*^7, 8.1561598*^7,
5.6950733*^7, 1.26664952*^8, 5.8734782*^7, 2.80816627*^8}, {}, None}}, None},
"ElementType" -> TypeSpecifier["Quantity"]["Real64", "People"]]]}}]]]];Tabular[tab, <|"KeyColumns" -> {"Year", "Country"}|>]用 RowKey 提取给定列的值:
%[RowKey[{2000, "Italy"}], "Population"]应用 (1)
tab = ResourceData["Sample Tabular Data: Fatal Collisions"]ColumnKeys[tab]Keys[tab]neworder = RotateRight[ColumnKeys[tab]]newtab = Tabular[tab[All, neworder], <|"KeyColumns" -> {"state"}|>]Keys[newtab]midwest = EntityValue[EntityClass["AdministrativeDivision", "USStatesMidwest"], EntityProperty["AdministrativeDivision", "StateAbbreviation"]]Tabular[newtab[RowKey[#]]& /@ midwest, <|"KeyColumns" -> {"state"}|>]属性和关系 (4)
下面是含有关键列的 Tabular 对象:
tab = Tabular[{{"one", True, "foo"}, {"two", False, "bar"}}, <|"ColumnKeys" -> {"key", "col1", "col2"}, "KeyColumns" -> {"key"}|>]可用 RowKey 提取行:
tab[RowKey["one"]]也可用 Key 封装提取表格中的行:
tab[Key["one"]]如果指定了关键列,Tabular 对象的 Keys 返回 RowKey 表达式列表:
Tabular[{{"cat", 2, 3}, {"dog", 5, 6}}, <|"ColumnKeys" -> {"a", "b", "c"}, "KeyColumns" -> {"a"}|>]Keys[%]Tabular[{{"cat", 2, 3}, {"dog", 5, 6}}, <|"ColumnKeys" -> {"a", "b", "c"}, "KeyColumns" -> {"a", "b"}|>]Keys[%]RowKey[{key1,key2,…}] 允许通过多个关键列的值对行进行索引:
Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["a" -> Association["ElementType" -> "String"],
"b" -> Association["ElementType" -> "Integer64"],
"c" -> Association["ElementType" -> "Integer64"]], "KeyColumns" -> {"a", "b"},
"Backend" -> "WolframKernel"], "BackendData" ->
Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{3, {0, 3, 6}, "catdog"}, {}, None},
"ElementType" -> "String"]], TabularColumn[Association["Data" -> {{2, 5}, {}, None},
"ElementType" -> "Integer64"]], TabularColumn[Association["Data" -> {{3, 6}, {}, None},
"ElementType" -> "Integer64"]]}}]]]][RowKey[{"cat", 2}]]%//NormalExtendedKey[key1,key2,…] 允许通过多个值指定列:
Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association[ExtendedKey["female", "name"] -> Association["ElementType" -> "String"],
ExtendedKey["female", "city"] -> Association["ElementType" -> "String"]],
"KeyColumns" -> None, "Backend" -> "WolframKernel"],
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{3, {0, 4, 13}, "AnnaElizabeth"}, {}, None},
"ElementType" -> "String"]], TabularColumn[Association[
"Data" -> {{3, {0, 7, 12}, "ChicagoParis"}, {}, None}, "ElementType" -> "String"]]}}]]]][All, ExtendedKey["female", "city"]]%//NormalRowKey 可以包含与 ExtendedKey 对象指定的列相对应的键:
tab = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association[ExtendedKey["first", "name"] -> Association["ElementType" -> "String"],
ExtendedKey["first", "a"] -> Association["ElementType" -> "Integer64"],
ExtendedKey["first", "b"] -> Association["ElementType" -> "Integer64"],
ExtendedKey["second", "name"] -> Association["ElementType" -> "String"],
ExtendedKey["second", "a"] -> Association["ElementType" -> "Integer64"],
ExtendedKey["second", "b"] -> Association["ElementType" -> "Integer64"]],
"KeyColumns" -> {ExtendedKey["first", "name"], ExtendedKey["second", "name"]},
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{3, {0, 3, 6}, "catdog"}, {}, None},
"ElementType" -> "String"]], TabularColumn[Association["Data" -> {{2, 5}, {}, None},
"ElementType" -> "Integer64"]], TabularColumn[Association["Data" -> {{3, 6}, {}, None},
"ElementType" -> "Integer64"]], TabularColumn[Association[
"Data" -> {{3, {0, 4, 9}, "rosetulip"}, {}, None}, "ElementType" -> "String"]],
TabularColumn[Association["Data" -> {{7, 10}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{8, 11}, {}, None}, "ElementType" ->
"Integer64"]]}}]]]];tab[RowKey[{"cat", "rose"}]]%//Normal相关指南
-
▪
- 表格对象
文本
Wolfram Research (2025),RowKey,Wolfram 语言函数,https://reference.wolfram.com/language/ref/RowKey.html.
CMS
Wolfram 语言. 2025. "RowKey." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/RowKey.html.
APA
Wolfram 语言. (2025). RowKey. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/RowKey.html 年
BibTeX
@misc{reference.wolfram_2026_rowkey, author="Wolfram Research", title="{RowKey}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/RowKey.html}", note=[Accessed: 13-July-2026]}
BibLaTeX
@online{reference.wolfram_2026_rowkey, organization={Wolfram Research}, title={RowKey}, year={2025}, url={https://reference.wolfram.com/language/ref/RowKey.html}, note=[Accessed: 13-July-2026]}