Wolfram Language

Quantities in Probability & Statistics

Working with Quantity-Valued Time Series

Analyze temperature variability at a given location.

In[1]:=
Click for copyable input
data = WeatherData[ Entity["City", {"Champaign", "Illinois", "UnitedStates"}], "Temperature", {{2016, 3, 20}, {2016, 3, 22}}];
In[2]:=
Click for copyable input
temps = TimeSeries[data, MissingDataMethod -> "Interpolation"]
Out[2]=

Visualize the temperature time series.

In[3]:=
Click for copyable input
DateListPlot[temps, PlotTheme -> "Detailed"]
Out[3]=

Basic properties.

In[4]:=
Click for copyable input
stats = {Min, Max, Mean, Median, StandardDeviation}; TableForm[{Map[#[temps] &, stats]}, TableHeadings -> {None, stats}]
Out[4]//TableForm=

Convert temperatures to degrees Fahrenheit.

In[5]:=
Click for copyable input
tempsF = UnitConvert[temps, "DegreesFahrenheit"]; TableForm[{Map[#[tempsF] &, stats]}, TableHeadings -> {None, stats}]
Out[5]//TableForm=

Find the 6-hour moving average.

In[6]:=
Click for copyable input
avg = MovingMap[Mean, temps, {Quantity[6, "Hours"], Center}]
Out[6]=
show complete Wolfram Language input
In[7]:=
Click for copyable input
DateListPlot[{temps, avg}, PlotLegends -> {"temperatures", "6-hour moving average"}, FrameLabel -> Automatic, PlotTheme -> "Detailed"]
Out[7]=

Related Examples

de es fr ja ko pt-br ru zh