how I should use MovingMap on a Dataset?

I am aware of How would I use Map on a Dataset column? still I cannot see how I should use MovingMap on a Dataset.

Even the identity functions does not work!

MovingMap[# &, dataset[[All, "Eons"]], 1]

My dataset is constructed like this

eons = {
{{2021, 02, 22}, 95},
{{2021, 02, 23}, 96},
{{2021, 02, 24}, 100},
{{2021, 02, 25}, 105}}

dataset =
Dataset[Map[Association[{"Date" -> #[[1]], "Eons" -> #[[2]]}] &,
eons]]


I can do things that are mere application of fuctions to a single row, e.g. Map[<|#, "Sqrt" -> Sqrt[#Eons]|> &, dataset ]. However using

MovingMap[# &, dataset[All, "Eons"], 1]


as suggested returns itself as output, which usually means mathematica does not know what to do.

• I believe you want MovingMap[# &, dataset[All, "Eons"], 1] - note the single brackets. You will need to give an example of your dataset for more help though :) Commented May 14, 2021 at 8:16
• Thanks for the susggestion, this too gives the same trouble as using Part or [[, mathematica return the input as output ... meaning it did not understand Commented May 14, 2021 at 8:31
• Indeed, it looks like MovingMap doesn't like to work directly on Dataset in this way. You can do either MovingMap[# &, Normal@dataset[All, "Eons"], 1] or dataset[MovingMap[(# &), #, 1] &, "Eons"]. Commented May 14, 2021 at 8:43
• From the help of MovingMap: "The data can be a list of values {Subscript[x, 1],Subscript[x, 2],[Ellipsis]}, a list of time-value pairs {{Subscript[t, 1],Subscript[x, 1]},{Subscript[t, 2],Subscript[x, 2]},[Ellipsis]}, a TimeSeries, EventSeries, or TemporalData.", but not Dataset. Commented May 14, 2021 at 15:31

As I posted in my comment: it looks like MovingMap doesn't like to work directly on Dataset in this way.

There are a few alternatives.

You can use the Dataset-style syntax to apply a function to a column's values:

dataset[MovingMap[(# &), #, 1] &, "Eons"]


You can do

MovingMap[# &, Normal@dataset[All, "Eons"], 1]


in order to convert the dataset's values into a simple list using Normal.

You can also convert your Dataset into TimeSeries data that MovingMap can operate directly on:

dataset =
Dataset[Map[
Association[{"Date" -> DateObject@#[[1]], "Eons" -> #[[2]]}] &,
eons]]
ts = TimeSeries@Normal@Values@dataset
MovingMap[# &, ts, 1] (* returns a TimeSeries as well *)

• I missed the fact that dataset[f,"columnName"] is essentially Apply to the column! Commented May 15, 2021 at 18:59