5
$\begingroup$

I have a nested dataset (a result of a JSON import done by Mathematica, curated for this example):

dataset=Dataset[
<|"sports" -> {
<|"id" -> 3, "name" -> "Baseball", "hasOfferings" -> True|>, 
<|"id" -> 4, "name" -> "Basketball", "hasOfferings" -> True|>, 
<|"id" -> 5, "name" -> "Beach Volleyball", "hasOfferings" -> False|>}|>
]

How do I extract a subset of the above, containing only the rows matching "hasOfferings" -> True ? I.e. the desired result would be:

Dataset[
<|"sports" -> {
<|"id" -> 3, "name" -> "Baseball", "hasOfferings" -> True|>, 
<|"id" -> 4, "name" -> "Basketball", "hasOfferings" -> True|>}|>
]

Based on the fact that

dataset[All, {1,2}] 

works as desired, I would have guessed that something like the following

dataset[All, "hasOfferings" == True]

would yield the desired filtering of the rows matching the condition, but it does not. Any help is appreciated.

$\endgroup$
3
$\begingroup$

Almost there:

 dataset[All, Select[#hasOfferings &]]
$\endgroup$
1
$\begingroup$

This should work: Query[Select[#hasOfferings == True &]]@dataset[#sports &]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.