We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [associations]

Questions on the associative data-structure introduced in Mathematica version 10.

Filter by
Sorted by
Tagged with
145
votes
3answers
10k views

How to make use of Associations?

I have been curious about it for long. Now that Mathematica 10 arrives, I think it's time to ask the question: How the new Association data structure would be used ...
61
votes
6answers
9k views

How can I add a column into a existing Dataset?

I'm very excited about the brand new Dataset function. I have played with it in Wolfram Cloud, and haven't figured out how can I add a new column into an existing <...
50
votes
3answers
4k views

Changing Values in an Association using Map

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as: ...
40
votes
2answers
2k views

Dataset vs an association of associations

Associations with a record structure (e.g., a flat table) can be organised in one of two main ways. First as a list of associations, which is also used in the case of Mathematica's data set ...
32
votes
4answers
867 views

How to organically merge nested associations?

Suppose I want to construct an association of associations, such as a list of people with attributes: ...
27
votes
3answers
340 views

Count works differently depending on how an association was created

Bug introduced in 10.4 and fixed in 11.3.0 I create two associations, that are supposed to be exactly the same. And then I want to count the elements at the second level. And I get different results: ...
25
votes
3answers
1k views

How can a key be renamed in an Association?

Consider an example Association: assoc = <|"a" -> 1, "b" -> "x", "this_key_is_too_long_to_type" -> {1}|>; ...
24
votes
1answer
453 views

Bug with Block & Lookup: Scope Variable Leak

After debugging a large chunk of code, I could identify this MWE. ...
24
votes
1answer
243 views

Bug with MapAt, Span, and Association?

Bug introduced in 10.0 and fixed in 11.0.0 Related to Mapping (Query) a function at multiple locations in nested data via All, Span, it seems to me that the behavior of ...
23
votes
1answer
432 views

Why do lookup times in Dataset and Association differ by orders of magnitude?

Consider the following three data structures: a list of rules, an association, and a dataset: ...
21
votes
2answers
889 views

Difference between Association and Dispatch

In the example below, Association has a different behavior from Dispatch: ...
20
votes
2answers
696 views

MatchQ-ing Associations (MMA 10)

Consider {x->1} which has FullForm List[Rule[x, 1]] and, therefore, ...
20
votes
1answer
735 views

Is there a practical way to define a default value for missing keys in an Association?

Clarification Although I may be missing his point I currently feel that Leonid's comments below are misleading. I am not looking for anything that is not already a part of ...
19
votes
4answers
570 views

Is it possible to avoid unpacking when merging Association?

For example, if we have assoc = AssociationThread[{1, 2, 3} -> RandomReal[1., {3, 10}]]; and ...
19
votes
3answers
2k views

Converting hierarchies of rules to associations

The impossibility of MatchQ-ing inside and Association MatchQ-ing Associations (MMA 10) explains a problem I have. I would like ...
19
votes
1answer
755 views

Learning Resources for Data Science in the Wolfram Language

I'm delivering an upcoming course on Data Science with the programming/analysis done predominantly in the Wolfram Language. I created the following table to leverage students' familiarity with Lists ...
18
votes
3answers
1k views

Assign names to Dataset columns

I am constructing a dataset like so: data = Dataset[AssociationThread[Keys[characterCounts], charFrequencies]] which gives me a dataset that looks like this: ...
18
votes
2answers
308 views

Association's Attributes change between 10.3.1 & 10.4?

In Mathematica 10.3.1 In[1]:= Attributes[Association] Out[1]= {Protected} In Mathematica 10.4: ...
17
votes
7answers
1k views

How to search Dataset to find all keys share same Value

If I have the following Dataset ...
17
votes
1answer
279 views

Aggregation queries on lists of associations in 10.3

Bug introduced in 10.3.0 and fixed in 10.3.1 Bug introduced in 10.3.0 and fixed in 10.4.0 First bug, see first part of the question Second bug, see update part Some aggregation queries applied to ...
17
votes
1answer
223 views

A bug in the overloading of MemberQ and FreeQ for Association?

Bug introduced in 10.0.0 and fixed in 10.1.0. While answering Pattern match for nested Association I came across behavior of MemberQ and ...
16
votes
3answers
828 views

Equivalent of ReplaceAll for Associations?

Is there a nice (built-in) way to apply Replace-style rules to key-value pairs in an association? Something like ...
16
votes
2answers
967 views

Change Values in Dataset under Condition

I have the following Dataset: ...
16
votes
4answers
467 views

ReplaceAll with Associations instead of Rules

I have just noticed that x /. <|x -> 123|> evaluates to 123 In other words, the association seems to behave as a ...
16
votes
1answer
271 views

Pattern matching to a function evaluation inside an Association

I find the following behaviour deeply counter-intuitive: <|1 -> 123.456 |> /. {x_?NumericQ -> Round[x]} (* <|1 -> Round[123.456]|> *) That ...
16
votes
2answers
297 views

Listable functions thread over Associations; is this documented?

Thanks to a somewhat misapplied use of MapThread I learned of this behavior: ...
15
votes
6answers
677 views

Reshaping associations, generalization of GroupBy

Let's say we have a set a\of associations: ...
15
votes
2answers
395 views

AssociationMap loses definition

Bug introduced in 10.0.0 and fixed in 10.1.0. I'm facing a strange behavior of AssociationMap. With a fresh Kernel session: ...
14
votes
3answers
276 views

Evaluated vs. unevaluated Association

This question might have a remote connection to my older question, it is also about sameness of expressions and subtle differences observable only in certain forms. I encountered this strange ...
14
votes
4answers
356 views

Association's Key[key] extraction different in V10.1/V10.2

V10.1: <|a -> 1|>[Key @ a] (* Missing["KeyAbsent", Key[a]]*) V10.0: <|a -> 1|>[Key @ a] (* 1 *) Bug or ...
14
votes
4answers
565 views

How can a field be efficiently added to a Dataset?

Let's use the example Dataset: ...
14
votes
1answer
225 views

Fractional Keys in Associations

I got into an unfortunate situation, involving fractions that can get changed by evaluation, which occur as (part of) keys in my associations. I will probably steer far away from the entire situation, ...
14
votes
1answer
376 views

Benefit of using Dataset to collect SQLSelect output

Considering a DatabaseExample included with Mathematica: ...
13
votes
8answers
2k views

Reverse Lookup: getting keys from values

Lists of Rules or Associations are both a useful way of mapping between values. It also ...
13
votes
3answers
651 views

How to “flatten” a nested Association?

For example, I have a nested association like this ...
13
votes
3answers
368 views

Dataset collapsing/reducing

I have a dataset ds with 3 columns named A, B, C. Columns A and B have repeated values. How can I obtain another dataset that contains a list of the values in C for ...
13
votes
2answers
346 views

Replace and Association

I'm surprised that I can't find this question already, so perhaps I'm missing something obvious. I would like to take a list of associations and remove any with value ...
13
votes
1answer
376 views

10.0.2 mapping Association to Dataset warning

Bug introduced in 10.0.2 and fixed in 10.0.3 In 10.0.2 ExampleData[{"Dataset", "Titanic"}][All, <| "gender" -> #sex|> &] Outputs the expected ...
13
votes
1answer
240 views

KeyDrop does not respect Key in V11

KeyDrop[<|a -> 1|>, Key[a]] <|a -> 1|> ...
13
votes
0answers
271 views

Slow JoinAcross performance

Bug introduced in 10.3 I am using JoinAcross to combine two datasets, where the key is an Integer. ...
12
votes
5answers
853 views

Applying a function to a Dataset column conditional on another slot's value

How to apply a function to a column conditional on another slot's value? The Dataset documentation show only how to apply a function to named slots independently. The ...
12
votes
3answers
344 views

Convert List of Associations into Association of Lists

For neural networks mathematica likes 2 ways to structure training sets: ...
12
votes
2answers
347 views

Pattern matching Association in rules

I would appreciate an explanation of how Associations behave in pattern matching, especially when matching rules, and using HoldPattern. Consider the following: ...
12
votes
5answers
405 views

Association of Associations : how to permute level 1 and level 2 keys?

I have a ragged Association of Association, say : ...
12
votes
1answer
146 views

Unexpected behavior of KeyTake

list = {{a, b, c, e}, {1, 2, b, h}, {"a", "h", 3, 5}}; asso = GroupBy[list, {#[[1]], #[[2]]} &] ...
12
votes
1answer
199 views

ReplaceAll behavior change from 10.2 to 10.3

Executing: ...
12
votes
0answers
170 views

Unix-like reference to parent and root Association?

Is there a syntax or function to reference parent and root when querying nested Associations similar to Unix' ".." and "/", eg "cd ../../mydir". ? Here's a typical application of the root construct....
11
votes
3answers
306 views

Move the outer key inward in an association

I have a list that looks like: ...
11
votes
3answers
852 views

Best way to handle nested Maps?

I often find myself working with lists of lists of data, gathering data, performing computations, and producing a variety of different sorts of output. Intuitively, it seems like this should be done ...
11
votes
2answers
378 views

Is there an idiomatic way to determine whether an `Association` is a subset of another?

I would like a way to tell if every key-value pair of an Association is contained in another. For instance, ...