Key

Key[key]

represents a key used to access a value in an association or a column in a Tabular object.

Key[key][assoc]

extracts the value corresponding to key in the association assoc.

Details

  • Key is used in functions such as Part to access values in Association objects or columns in Tabular objects.
  • Key can normally be omitted when key is a string.

Examples

open allclose all

Basic Examples  (2)

Extract a value from an association as a part:

Extract a value from an association by function application:

Extract a column from a Tabular object:

Scope  (6)

The Key wrapper is not necessary when the key is a string:

Lookups in associations interoperate with parts in lists and other expressions:

The explicit Key can be omitted when the keys in an association are strings:

Key is normally generated by functions such as Position:

Use Extract to extract the values:

For expressions at deeper levels, the positions can be combinations of integers and Key objects:

Use Key to disambiguate between an integer index and an integer key:

assoc[[Key[key]]] is equivalent to assoc[key], including integer keys:

Take a Tabular object with several columns:

Columns with non-string keys require the explicit use of Key for Part extraction:

String keys can be used with or without a Key wrapper:

Repeated keys are treated as one, even if they are wrapped with Key:

Take a Dataset object with several rows:

Use Part to extract a row with a string key:

Alternatively, use ds[key], which is equivalent to Query[key][ds]:

For non-string keys, extraction requires wrapping them with Key:

Otherwise, Query will interpret the key as a function to be used on the row:

Applications  (1)

Use Key in the Function body of Tabular transformations when the key is a general expression:

Properties & Relations  (2)

Key always takes one argument:

ExtendedKey can take more than one argument:

Both keys can then be used to address their values:

Take a Tabular object with a key column:

Key wrappers can be used to extract tabular rows and columns:

Row extraction can also be performed with RowKey:

Wolfram Research (2014), Key, Wolfram Language function, https://reference.wolfram.com/language/ref/Key.html (updated 2025).

Text

Wolfram Research (2014), Key, Wolfram Language function, https://reference.wolfram.com/language/ref/Key.html (updated 2025).

CMS

Wolfram Language. 2014. "Key." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/Key.html.

APA

Wolfram Language. (2014). Key. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Key.html

BibTeX

@misc{reference.wolfram_2024_key, author="Wolfram Research", title="{Key}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Key.html}", note=[Accessed: 20-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_key, organization={Wolfram Research}, title={Key}, year={2025}, url={https://reference.wolfram.com/language/ref/Key.html}, note=[Accessed: 20-January-2025 ]}