2

I've executed this instruction in Wolfram Mathematica as Wolfram Alpha Query

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

and in 'a' there are stored the data that are in my interest.

The question is: how can I output a grid with only important data, like 'date' and 'tone /year' for each year??

A simple grid that compare the coffee consumption between italy and england sorted by date.

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

3 Answers3

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}}]

enter image description here

Table output

TableForm[{#1[[1, 1]], #1[[2, 1]], #2[[2, 1]]} & @@@ c,
 TableHeadings -> {None, {"Year", "Italy", "England"}}]
Chris Degnen
  • 8,443
  • 2
  • 23
  • 40
2

An alternative to using the WolframAlpha function is to use EntityValue:

DateListPlot@EntityValue[
    {Entity["Country","Italy"],Entity["Country","UnitedKingdom"]},
    EntityProperty["Country","AgricultureConsumption", {"AgricultureProduct"->"Coffee","Date"->All}]
]
Carl Woll
  • 146
  • 3
0

for completeness, this is how to directly use the result from the question:

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

note it is directly usable by DateListPlot:

DateListPlot[a]

enter image description here

confirm the dates from the two data sets are the same :

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

True

now the table:

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

enter image description here

note this relies on a bit of faith that alpha supplied the results in the order as posed in the question. The other approaches are probably more robust.

agentp
  • 6,849
  • 2
  • 19
  • 37