我已在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
....
...
..
.
答案 0 :(得分: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"}}]
答案 1 :(得分:2)
使用WolframAlpha函数的另一种方法是使用EntityValue:
DateListPlot@EntityValue[
{Entity["Country","Italy"],Entity["Country","UnitedKingdom"]},
EntityProperty["Country","AgricultureConsumption", {"AgricultureProduct"->"Coffee","Date"->All}]
]
答案 2 :(得分: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按照问题中提供的顺序提供结果。其他方法可能更强大。