Message Boards Message Boards

Intuitive understanding of the Dataset operation sequence

Posted 6 years ago

In <An elementary introduction to Wolfram Language> Chapter 45 example 42 ( In[42] )

                planets[All, "Moons", NumberLinePlot[Values[#]] &, Log[#Mass/Quantity[1, "EarthMass"]] &]

This gives a number line plot of the masses of the moons for different planets. I couldn't figured out why it worked and both the documentation and the tutorials weren't very helpful.

Eventually I figured it out myself. One reads this function forward and then backward, visualizing in ones head not tables but associations. Focus on selections when reading forward, operations when reading backward.

In this case:

Reading forward: {a list of associations whose keys are planets} -> Select all planets -> {for each planet a list of associations whose keys are its fields("Mass","Radius","Moons") } -> Select "Moons" -> {for field "Moon" a list of associations whose keys are the name of moons} -> Select All (All is equivalant to #& in this case) -> {for each moon a list of associations whose keys are its fields("Mass","Radius")} -> Select "Mass"

Reading backward: {"Mass" of a specific moon} -> Log["Mass"/EarthMass] -> {Log["Mass"/EarthMass] of a specific moon} -> Step Back -> {a list of associations whose keys are moon name and values are Log["Mass"/EarthMass]} -> Take its Values -> {A list of Log["Mass"/EarthMass]} -> Make a NumberLinePlot -> {A number line plot} -> Step Back -> {a list of associations whose keys are the planets and values are number plots} -> Select All (reading backwards we only need to step backward twice, since the forward specification has "Moons" and "Mass" these two field specification, which decreasedenter code here the dimension of the nested associations)

I hope this is helpful for those who just can't wrap their head around the ascending and descending sequence of operations for the dataset.

POSTED BY: LYU Liuke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract