处理值为数量的时间序列
分析给定地点的气温变化情况.
In[1]:=
![Click for copyable input](assets.zh/working-with-quantity-valued-time-series/In_91.png)
data = WeatherData[
Entity["City", {"Champaign", "Illinois", "UnitedStates"}],
"Temperature", {{2016, 3, 20}, {2016, 3, 22}}];
In[2]:=
![Click for copyable input](assets.zh/working-with-quantity-valued-time-series/In_92.png)
temps = TimeSeries[data, MissingDataMethod -> "Interpolation"]
Out[2]=
![](assets.zh/working-with-quantity-valued-time-series/O_64.png)
可视化温度时间序列.
In[3]:=
![Click for copyable input](assets.zh/working-with-quantity-valued-time-series/In_93.png)
DateListPlot[temps, PlotTheme -> "Detailed"]
Out[3]=
![](assets.zh/working-with-quantity-valued-time-series/O_65.png)
基本属性.
In[4]:=
![Click for copyable input](assets.zh/working-with-quantity-valued-time-series/In_94.png)
stats = {Min, Max, Mean, Median, StandardDeviation};
TableForm[{Map[#[temps] &, stats]}, TableHeadings -> {None, stats}]
Out[4]//TableForm=
![](assets.zh/working-with-quantity-valued-time-series/O_66.png)
把温度的单位转换成华氏度.
In[5]:=
![Click for copyable input](assets.zh/working-with-quantity-valued-time-series/In_95.png)
tempsF = UnitConvert[temps, "DegreesFahrenheit"];
TableForm[{Map[#[tempsF] &, stats]}, TableHeadings -> {None, stats}]
Out[5]//TableForm=
![](assets.zh/working-with-quantity-valued-time-series/O_67.png)
计算 6-小时的移动平均.
In[6]:=
![Click for copyable input](assets.zh/working-with-quantity-valued-time-series/In_96.png)
avg = MovingMap[Mean, temps, {Quantity[6, "Hours"], Center}]
Out[6]=
![](assets.zh/working-with-quantity-valued-time-series/O_68.png)
显示完整的 Wolfram 语言输入
Out[7]=
![](assets.zh/working-with-quantity-valued-time-series/O_69.png)