I tried this code, which downloads data from several weather stations.

a ={"WMO44203", "WMO44207", "WMO44210", "WMO44212"}` 
dset = WeatherData[#, "Temperature", {{1990, 8, 2, 12, 0, 0}, {1991, 8, 2, 12, 0, 0}}] & /@ a

But I have written the following code to export the data from a single weather station:

ubt = WeatherData["WMO44292",  "Temperature" , 
 {{1956, 1, 1, 0, 0}, {2015, 4, 1, 0, 0}}, TimeZone -> +8]    
b = Normal[ubt]    
shifted = TimeSeriesShift[ubt, Quantity[8, "Hour"]];    
Tshift = Append[DateList[#[[1]]], QuantityMagnitude[#[[2]]]] & /@ 
Tsh = Tshift /. (0.) -> 0    
Tsh = Grid[Tsh]    
Export["44292TemShift.dat", Tsh]

I would like to download and export the data from many weather stations. Can anyone help me?

  • $\begingroup$ Do you mean you want to Export many weather stations data at once or to separate files? Also please dont forget to Accept any Answers to previous questions by Hitting the Tick Mark next to your preferred answer. $\endgroup$ Apr 27, 2015 at 5:48
  • 2
    $\begingroup$ I think what you want is something like #["Path"] & /@ shifted at the end of your Tshift = line. Path is not working in that line because its trying to use a List of 4 separate time series, and Mathematica doesn't know how to do that directly. So we use Map (@) to pass 1 time series at a time to Path and the rest of the code on that line. Its worth spending some time trying to understand Map its pretty key to huge ranges of mathematica functionality. $\endgroup$ Apr 27, 2015 at 5:57
  • $\begingroup$ How to separate time series? $\endgroup$
    – teegii
    Apr 27, 2015 at 7:33
  • $\begingroup$ b = shifted[[1, All, 1]] DateList[#] & /@ b. This code worked successfull.DateList[#[[1, All, 1]]] & /@ shifted["Path"]. This code not working.Why? $\endgroup$
    – teegii
    Apr 27, 2015 at 7:33
  • $\begingroup$ because normal changes the list of 4 timeseries into a list of lists, which is simple to map. shifted is a list of 4 Timeseries, and "Path" is trying to operate on the outer List not the underlying Timeseries. $\endgroup$ Apr 27, 2015 at 8:18

1 Answer 1


This is a quick and dirty version for what I think you are trying to do. Note that its not good Stack Exchange practise to keep asking variations of the question. One caveat with the Export help is that most useful stuff is held under each file format - so try looking at the help for XLSX.

a = {"WMO44203", "WMO44207", "WMO44212"};

dset = WeatherData[#, 
"Temperature", {{1956, 1, 1, 0, 0}, {2015, 4, 1, 0, 0}}, 
TimeZone -> +8] & /@ a

If we create a nested list for the date instead of using Append in your example, we can get the entire date in one excel cell. i.e. {date}, value. You could also still use the Append version in your question and then use & and DateValue in Excel to convert the values to a date. eg =DateValue(a1&'\'&b1&'\'&c1)

exports = {DateList[#[[1]]], #[[2]]} & /@ #["Path"] & /@ dset;

"Sheets" -> {"WMO44203" -> exports[[1]], "WMO44207" -> exports[[2]], 
"WMO44212" -> exports[[3]]}, "Rules"]

Edit To use this with n sheets where n= number of weather stations :

Export["test.xlsx", "Sheets" -> Rule @@@ Transpose@{a, exports}, "Rules"]

Taken directly from @Belisarius answer here


There may be a small bug - on my Excel (2011 for Mac) the export creates a file that Excel thinks is corrupt - if you accept the repair it gives the last sheet still as a Mathematica List in cell A1 rather than Rows/Columns. As a work around I would suggest exporting the last Station twice and then just deleting the last sheet after the repair.


If you get Java errors try increasing the Java Heap size with the following, if it still fails try changing 2048 by multiples of 1024 e.g. 3072, 4096 etc :

Export::nojmem: There was insufficient Java heap space for the operation

<< JLink`;
ReinstallJava[CommandLine -> "java", JVMArguments -> "-Xmx2048m"];
  • $\begingroup$ Thank you. But my data is all temperature. from 1956 to 2015 data is very large. 300000 row datas. XLSX have 65000 row capacity. $\endgroup$
    – teegii
    Apr 27, 2015 at 12:21
  • $\begingroup$ a is stations 60. this code is example $\endgroup$
    – teegii
    Apr 27, 2015 at 12:33
  • $\begingroup$ XLSX as a format doesn't have a 65k restriction, and neither does Mathematica when you export to it, the row restrictions are built into the Excel version, not the file format. Especially since we create a separate tab for each weather station. Let me see what I can do when Length[a]=60 $\endgroup$ Apr 27, 2015 at 18:06
  • $\begingroup$ Choose a matlink program to launch. What a choose? $\endgroup$
    – teegii
    Apr 27, 2015 at 23:20
  • $\begingroup$ Export["weather.xlsx", "Sheets" -> {"WMO44203" -> exports[[1]], "WMO44207" -> exports[[2]], "WMO44212" -> exports[[3]]}, "Rules". This code have error. Export::nojmem: There was insufficient Java heap space for the operation. Try increasing the Java Virtual Machine heap size. >>. therefore I written` << JLink; InstallJava[]; ReinstallJava[CommandLine -> "java", JVMArguments -> "-Xmx2048m"]. but Choose a matlink program to launch. I don't know what a choose. $\endgroup$
    – teegii
    Apr 28, 2015 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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