Search code examples
wolfram-mathematicawolframalphawolfram-language

print Grid with list in list as output from Wolfram Alpha


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
....
...
..
.

Solution

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