Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have used WolframAlpha since it was launched (now a pro member) but am new to Mathematica 8. Is there a way to automatically add data from WA to a Mathematica dataset? For example, what if I have data on annual sales and I want to add the USA's GDP in the given year as the third column. I have used the WolframAlpha[] function but am not sure how to integrate it into my data. I'd want to add a "GDP" column to this data:

In[4]:= sales = Import["C:\\Users\\Andrew\\Desktop\\DemoData.xlsx"]

Out[4]= {{{"Year", "Sales"}, {2000., 105704.}, {2001., 
120042.}, {2002., 118973.}, {2003., 126539.}, {2004., 
105582.}, {2005., 126510.}, {2006., 101745.}, {2007., 
105821.}, {2008., 127313.}, {2009., 100908.}, {2010., 
115692.}, {2011., 116188.}}}

This isn't the best example, but this kind of thing would make my grad school life markedly easier. No more downloading, cleaning, and merging independent variable sets from random sources!

share|improve this question
up vote 8 down vote accepted

You can access historical GPD data via the WolframAlpha command like so:

gdpData = WolframAlpha["us gdp",

This returns quarterly data going back to 1947 in a structured list. You can manipulate the data just as you would any data in Mathematica. Thus, you can get the data points at the first of the year in the date range desired like so:

gdpDataRestricted = First/@ SplitBy[Select[gdpData, 

You can then combine it with your data and display the result.

yourData = {{2000.,105704.},{2001.,120042.},{2002.,118973.},
allData = Table[Append[yourData[[k]],gdpDataRestricted[[k,-1]]],
Grid[Prepend[allData,{"Year","Sales", "GDP"}], Dividers -> All]

enter image description here

Figuring out the WolframAlpha command can be tricky. I usually start with the most basic command (in this case, WolframAlpha["us gdp"]) and then use the + signs in the upper right portion of the pods to find the correct invocation to get at the actual data.

share|improve this answer
+1 I was just about to edit your post and include a screenshot how one can extract the specific WolframAlpha call when you added it ;-) – halirutan Aug 17 '12 at 3:23
Exactly what I wanted! You'd be surprised at how many researchers, professors, and TAs spend hours adding data by processing and combining data files. – Andrew Brēza Aug 17 '12 at 3:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.