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

  • 1
    $\begingroup$ You've seen WeatherData[]? $\endgroup$ Oct 12, 2012 at 8:23
  • $\begingroup$ You can get the data out of Wolfram|Alpha pretty easily. Take a look at this article for an example: support.wolfram.com/kb/7357 The data here is financial, but the process is the same. $\endgroup$
    – Searke
    Oct 12, 2012 at 14:41

1 Answer 1


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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