Dataset¶
Wraps data with type information for structured data handling.
A dataset is queried with the same successive-level operator spec Query takes.
An operator that yields a collection gives back a dataset,
while one that yields an atom returns it bare.
$ wo 'Normal[Dataset[{<|"a" -> 1|>, <|"a" -> 2|>, <|"a" -> 3|>}][Select[#a > 1 &]]]'
{<|a -> 2|>, <|a -> 3|>}
An integer selects a row:
Statistics and list functions applied to a dataset see the data it wraps,
not its internal Dataset[data, type, metadata] structure:
A function that reduces to a single value returns it bare, while one that yields a collection gives back a dataset:
Part indexes the data as well:
A string in a grouping or sorting operator extracts that key:
$ wo 'Normal[Dataset[{<|"a" -> 1, "b" -> 5|>, <|"a" -> 1, "b" -> 6|>}][GroupBy["a"]]]'
<|1 -> {<|a -> 1, b -> 5|>, <|a -> 1, b -> 6|>}|>
The operator form of Query applies the same spec to a dataset:
A bare rule at an operator position is read as an option to Query,
so the level is left untouched:
$ wo 'Normal[Dataset[{<|"a" -> 1|>, <|"a" -> 2|>}][All, "a" -> "b"]]'
OptionValue::nodef: Unknown option a for Query.
{<|a -> 1|>, <|a -> 2|>}
A dataset is an atom for traversal, while Length and Dimensions
still describe the data it wraps: