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 moved to another city and the weather sucks.

Sometimes I feel like getting sad and so I go to wolfram|alpha and check for example


enter image description here


Today I feel like getting depressed.

Consequently I wonder if there is a way to import all the data into Mathematica and write a function


which should evaluate to

$$ \frac{ \int_{\text{date 1}}^{\text{date 2}} \left(T_{\text{city 2}}(t)-T_{\text{city 1}}(t)\right) \text dt } { t_{\text{date 2}}-t_{\text{date 1}} },$$

$T_{\text{city X}}(t)$ being the temperature in $\text{city X}$ at time $t$.

share|improve this question
You've seen WeatherData[]? – J. M. Oct 12 '12 at 8:23
You can get the data out of Wolfram|Alpha pretty easily. Take a look at this article for an example: The data here is financial, but the process is the same. – Searke Oct 12 '12 at 14:41
up vote 5 down vote accepted

As suggested by @J.M. you don't need WolframAlpha. One way is to define :

temperatureComparison[{city1_, city2_}, {date1_, date2_}] := 
 Module[{data1, data2, int1, int2},
  data1 = {AbsoluteTime[#[[1]]], #[[2]]} & /@  WeatherData[city1, "MeanTemperature", {date1, date2, "Day"}] ;
  data2 = {AbsoluteTime[#[[1]]], #[[2]]} & /@ WeatherData[city2, "MeanTemperature", {date1, date2, "Day"}] ;
  int1 = Interpolation[data1];
  int2 = Interpolation[data2];
  {#, NIntegrate[
   int1[t] - int2[t], {t, AbsoluteTime[date1], 
    AbsoluteTime[#]}]/(AbsoluteTime[#] - AbsoluteTime[date1])} & /@    
     NestList[DatePlus[#, 1] &, DatePlus[date1, 1], Round@DateDifference[date1, date2] - 1]


which you can use as :

output = temperatureComparison[{"Rome", {"London", "GreaterLondon",  
     "UnitedKingdom"}}, {{2012, 1, 1}, Date[]}]


enter image description here

share|improve this answer

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.