# Tag Info

## Hot answers tagged query

Accepted

### Visualizing Type System Operations

This response defines a function called traceTypes which provides a quick-and-dirty visualization of type system operation. The function is somewhat fragile as it ...
• 67k
Accepted

### Struggling to understand Query

Short Answer The query operator for a given level can perform both descending and ascending actions, separated by the /* operator. We can tack the descending ...
• 67k
Accepted

### Query: adding additional operator changes meaning of preceding operators

This is a corner case that occurs when ascending operators are interleaved between descending operators. This case falls into an undocumented grey area. In the Details and Options section of the ...
• 67k
Accepted

### Transpose fail in 11.1 Dataset

As observed in the question, the problem lies with the type information of the dataset. Specifically, the type information for the innermost association is missing (i.e. "any type"). This causes the ...
• 67k

### Slicing an Association with named key span without normalizing?

I don't know if this is useful to you but it seems a little cleaner than your own code: ...
• 264k
Accepted

### Query datasets with "variable" named slots

These work: d[Select[#[colname] > 3 &]] In the Details section of Slot, it is said that "# is equivalent to Slot[1]" so it is equivalent to write: ...
• 7,195

### 10.0.2 breaks a recursive "trie" query

There appears to be a bug in the type inference mechanism here. If you evaluate <<Dataset <<TypeSystem and then ...
• 2,106
Accepted

### How to filter this nested list of Association

We must adjust the Select operator to account for the fact that the keys "a" and "b" are ...
• 67k

### How does Query decide the order in which the functions are applied?

@Lee's answer shows how to circumvent the problem by using RightComposition (/*) instead of ...
• 23.4k
Accepted

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

Here is one way: data[All, MapAt[foo, #, #PLATFORM /. {"Dropbox" -> "LOCATION", _ -> {}}] &] Or, if one prefers If: ...
• 67k

### Query datasets with "variable" named slots

@SquareOne's answer shows the natural, idiomatic way to express the query. It exploits the fact that an association can be applied to a key to extract that key's value. A similar work-around would ...
• 67k
Accepted

### A subtlety in Query

The behaviour is by design. When we query a Dataset, the system tries to infer whether we wish the result to be a dataset itself, or just a simple value. The ...
• 67k

### Simplifying a reverse Fold for a Query

A more direct solution with Fold using Range to reverse. With ...
• 39.3k

### Does anyone know a way to use patterns in Query?

There is no built-in facility to do this kind of transformation, but we can define our own query operator like so: ...
• 67k
Accepted

### How can I understand this example of Query taken from current Mathematica documentation?

This is "ascending" sub-query operator syntax. It operates on the entire row to produce a new row with the specified keys and values as the operator applied to the row. However, the ...
• 39.3k
Accepted

### Aggregation queries on lists of associations in 10.3

As confirmed by @Stefan R, it is a bug in 10.3. In the meanwhile, a possible workaround is : Merge[xx, Mean]
• 7,195

### A subtlety in Query

I'm not sure I'm missing something here, but as far as I can see, you should regard this as a feature. When you evaluate your Query, one of the later steps is to ...
• 111k

### Problem constructing Association tables with some operators

This appears to be another example of the WRI-acknowledged bug described in Possible bug involving Dataset/Query and RightComposition. In short, the query is being "compiled" into an expression that ...
• 67k
Accepted

### Does anyone know a way to use patterns in Query?

Since I am not aware of any built-ins, here is another custom solution: ...
• 23.4k
Accepted

### Filtering Query Nested Data (Dataset and Association)

The following query will return the desired result: ...
• 67k

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

Okay, this question is already answered, but I want to add my 'preferred way' here: First, we define a new operator: ...
• 10.5k

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

Perhaps, there is a better one, but here is one that comes to mind: ClearAll[transform]; transform["Dropbox"] := foo; transform[_] := Identity; and then ...
• 111k

### Large Dataset query fails if column contains Missing

Extended comment converted to a non-answer, nailing down what is required to trigger this bug: Here's a simple Dataset with one key having all string values, ...
• 62.6k

### Unexpected behavior of PreIncrement when querying associations

The 2nd example given under Query > Properties & Relations tells us Before being applied, Query expressions are "compiled" into ordinary compositions of ...
• 106k
Accepted

### Query inside Dynamic triggers continuous high CPU load for FE

A quick fix is to add TrackedSymbols :> {searchstring} to the Dynamic. But at the end it is just another example from a ...
• 132k

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

Here is another relatively straightforward approach: data[All, <|#, "LOCATION" -> If[#PLATFORM == "Dropbox", foo[#LOCATION], #LOCATION]|> &] Or ...
• 1,126
Accepted

### Query and Dataset Syntax Peculiarities

Let's go through it blow-by-blow... Query[DeleteMissing] @ d1 This will apply DeleteMissing to the list of associations. The documentation says: DeleteMissing[...
• 67k

### Getting slices of a nested Association via Query

This will work: db // Query[ Drop[ #, None, {3} ]& @* Transpose, 2, 1 ;; 3 ] {<|"English" -> "a", "Greek" -> "α"|>, <|"English" -> "b", "Greek" -...
• 12.3k

### Applying a function by Key pattern, preserving Association order

This should do what you want: ...
• 2,791