2

我已经在 Wolfram Mathematica 中作为 Wolfram Alpha Query 执行了这条指令

a = WolframAlpha[
  "italy vs england coffee consumption", \
    {{"History:AgricultureConsumption:AgricultureData", 1}, 
   "ComputableData"}]

并且在“a”中存储了我感兴趣的数据。

问题是: 我怎样才能输出一个只有重要数据的网格,比如每年的“日期”和“音调/年”?

一个简单的网格,比较意大利和英国之间按日期排序的咖啡消费量。

date | italy | england
----------------------
1961 | 11111 | 2222222
1962 | 11112 | 2222223
....
...
..
.
4

3 回答 3

2
a = WolframAlpha["italy coffee consumption",
{{"History:AgricultureConsumption:AgricultureData", 1},
    "ComputableData"}];

b = WolframAlpha["england coffee consumption",
{{"History:AgricultureConsumption:AgricultureData", 1},
    "ComputableData"}];

(* select common dates *)
dates = Intersection[First /@ a, First /@ b];

Labeled[DateListPlot[Transpose[c = Flatten[{
       Cases[a, {#, _}],
       Cases[b, {#, _}]}, 1] & /@ dates],
  PlotLegends -> {"Italy", "England"}], "t/yr", {{Top, Left}}]

在此处输入图像描述

表输出

TableForm[{#1[[1, 1]], #1[[2, 1]], #2[[2, 1]]} & @@@ c,
 TableHeadings -> {None, {"Year", "Italy", "England"}}]
于 2016-07-12T20:08:19.807 回答
2

使用 WolframAlpha 函数的替代方法是使用 EntityValue:

DateListPlot@EntityValue[
    {Entity["Country","Italy"],Entity["Country","UnitedKingdom"]},
    EntityProperty["Country","AgricultureConsumption", {"AgricultureProduct"->"Coffee","Date"->All}]
]
于 2016-12-23T01:14:50.377 回答
0

为了完整起见,这是如何直接使用问题的结果:

a = WolframAlpha[
  "italy vs england coffee consumption", \
{{"History:AgricultureConsumption:AgricultureData", 1}, 
   "ComputableData"}]

请注意,它可以直接使用DateListPlot

DateListPlot[a]

在此处输入图像描述

确认两个数据集的日期相同:

a[[1, All, 1]] == a[[2, All, 1]]

真的

现在的表:

TableForm[
  MapThread[{DateString[#1[[1]], "Year"], 
    Sequence @@ ((Round@QuantityMagnitude[#[[2]]]) & /@ {##})} &, a], 
    TableHeadings -> {None, {"Year", "Italy", "England"}}]

在此处输入图像描述

请注意,这依赖于一点信念,即 alpha 按问题中提出的顺序提供结果。其他方法可能更健壮。

于 2016-12-23T15:26:38.330 回答