3
$\begingroup$

I have the following data set:

dataset = Dataset[{
<|"County" -> "ALACHUA", "Adjacent_County" -> "BRADFORD", 
 "City" -> "BROOKER"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "BRADFORD", 
 "City" -> "HAMPTON"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "BRADFORD", 
 "City" -> "LAWSEY"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "BRADFORD", 
 "City" -> "STARKE"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "COLUMBIA", 
 "City" -> "LAKECITY"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "GILCHRIST", 
 "City" -> "FANNINGSPRINGS"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "GILCHRIST", 
 "City" -> "TRENTON"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "LEVY", 
 "City" -> "CEDARKEY"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "LEVY", 
 "City" -> "CHIEFLAND"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "LEVY", 
 "City" -> "FANNINGSPRINGS"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "LEVY", 
 "City" -> "WILLISTON"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "MARION", 
 "City" -> "BELLEVIEW"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "MARION", 
 "City" -> "DUNNELLON"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "MARION", 
 "City" -> "OCALA"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "PUTNAM", 
 "City" -> "CRESCENTCITY"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "PUTNAM", 
 "City" -> "PALATKA"|>,
<|"County" -> "ALACHUA", "Adjacent_County" -> "UNION", 
 "City" -> "LAKEBUTLER"|>}];

What Mathematica command should I use so that if I query: "FANNINGSPRINGS"; the evaluation of the command returns: {"GILCHRIST", "LEVY"}. This means that Fanning Springs is a city located at two counties; namely Gilchrist and Levy, that are adjacent to Alachua County. Thank you!

$\endgroup$

2 Answers 2

4
$\begingroup$

You can use GroupBy to do this:

dataset[GroupBy["City"] /* "FANNINGSPRINGS", All, "Adjacent_County"]

enter image description here

Using Normal to get the raw list outout:

dataset[GroupBy["City"] /* "FANNINGSPRINGS", All, "Adjacent_County"] // Normal

{"GILCHRIST", "LEVY"}

You can also simply select by the "City" field:

ds[Select[#City == "FANNINGSPRINGS" &], "Adjacent_County"]
$\endgroup$
2
  • $\begingroup$ Thank you Carl! I accept your answer. $\endgroup$ Commented Aug 2, 2019 at 17:18
  • 2
    $\begingroup$ Happy to help. To accept an answer, click the checkmark underneath the vote counter on the left :) $\endgroup$
    – Carl Lange
    Commented Aug 3, 2019 at 0:06
2
$\begingroup$
dataset[Select[#[[3]] == "FANNINGSPRINGS" &]]
$\endgroup$
1
  • 1
    $\begingroup$ You could also use the key here: ds[Select[#City == "FANNINGSPRINGS" &]] - or if the key has spaces you can quote it like ds[Select[#"Key With Space" == "FANNINGSPRINGS" &]] $\endgroup$
    – Carl Lange
    Commented Aug 2, 2019 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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