GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • WOLFRAM
  • Products
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App
  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs
  • Wolfram AI Ecosystem

This view

  • Original page
  • New address

GeezerVison is showing reference.wolfram.com — Key—Wolfram Documentation

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
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Applications  
Properties & Relations  
See Also
Related Guides
Related Links
History
Cite this Page

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 all close all

Basic Examples  (2)

Extract a value from an association as a part:

Wolfram Language code: <|a -> b, c -> d|>[[Key[a]]]

Extract a value from an association by function application:

Wolfram Language code: <|a -> b, c -> d|>[a]

Extract a column from a Tabular object:

Wolfram Language code: Tabular[{<|a -> 1, b -> 2, c -> 3|>, <|a -> 4, b -> 5, c -> 6|>}]
Wolfram Language code: %[[All, Key[b]]]

Scope  (6)

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

Wolfram Language code: <|"a" -> b, "c" -> d|>[["a"]]

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

Wolfram Language code: {<|a -> x, b -> {y, z}|>, w}[[1, Key[b], 2]]

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

Wolfram Language code: {<|"a" -> x, "b" -> z|>}[[1, "b"]]
Wolfram Language code: <|"a" -> b, "c" -> d|>["a"]

Key is normally generated by functions such as Position:

Wolfram Language code: Position[<|a -> 1, b -> 2|>, _Integer]

Use Extract to extract the values:

Wolfram Language code: Extract[<|a -> 1, b -> 2|>, %]

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

Wolfram Language code: Position[{<|"a" -> 1, "b" -> <|"b1" -> 2, "b2" -> 3|>|>}, _ ? OddQ]

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

Wolfram Language code: assoc = <|2 -> "a", 1 -> "b"|>;
Wolfram Language code: assoc[[2]]
Wolfram Language code: assoc[[Key[2]]]

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

Wolfram Language code: % === assoc[2]

Take a Tabular object with several columns:

Wolfram Language code: tab = Tabular[{{1, True, Today}, {2, False, Tomorrow}}, {"col", bool, "date"}]

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

Wolfram Language code: tab[[All, {"col", Key[bool]}]]

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

Wolfram Language code: tab[[All, {"col", Key["date"]}]]

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

Wolfram Language code: tab[[All, {"date", Key["date"]}]]
Wolfram Language code: FromTabular[tab, "Dataset"]//Normal

Take a Dataset object with several rows:

Wolfram Language code: ds = Dataset[<|"col" -> 1, bool -> True, "date" -> DateObject[{2024, 11, 21}, "Day"]|>]

Use Part to extract a row with a string key:

Wolfram Language code: ds[["col"]]

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

Wolfram Language code: ds["col"]
Wolfram Language code: Query["col"][ds]

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

Wolfram Language code: ds[[Key[bool]]]
Wolfram Language code: ds[Key[bool]]

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

Wolfram Language code: ds[bool]
Wolfram Language code: Query[bool][ds]

Applications  (1)

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

Wolfram Language code: tab = ToTabular[{f[x] -> Power[Sin[x] ^ Range[5]]}, "Columns"]
Wolfram Language code: TransformColumns[tab, f'[x] -> Function[D[#[Key[f[x]]], x]]]
Wolfram Language code: TransformColumns[tab, f'[x] -> Function[D[Slot[Key[f[x]]], x]]]

Properties & Relations  (2)

Key always takes one argument:

Wolfram Language code: key = Key["k"]

ExtendedKey can take more than one argument:

Wolfram Language code: ekey = ExtendedKey["a", "b", "c"]

Both keys can then be used to address their values:

Wolfram Language code: assoc = <|key -> "foo", ekey -> "bar"|>;
Wolfram Language code: assoc[key]
Wolfram Language code: assoc[ekey]

Take a Tabular object with a key column:

Wolfram Language code: tab = Tabular[{{"one", True, "foo"}, {"two", False, "bar"}}, <|"ColumnKeys" -> {"key", "col1", "col2"}, "KeyColumns" -> {"key"}|>]

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

Wolfram Language code: tab[Key["one"]]
Wolfram Language code: tab[[All, Key["col2"]]]

Row extraction can also be performed with RowKey:

Wolfram Language code: tab[RowKey["one"]]

See Also

Part  Association  Tabular  Keys  KeyExistsQ  ExtendedKey  RowKey

Related Guides

    ▪
  • Associations
  • ▪
  • Function Composition & Operator Forms
  • ▪
  • Tabular Objects

Related Links

  • An Elementary Introduction to the Wolfram Language : Associations

History

Introduced in 2014 (10.0) | Updated in 2025 (14.2)

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_2026_key, author="Wolfram Research", title="{Key}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Key.html}", note=[Accessed: 12-November-2026]}

BibLaTeX

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

Top
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.