In answering a question about how to get data out of Wunderground using Python I realised just how simple it is.

This snippet has all you need to collect daily data for sequential dates at a given weather station and write it to a CSV file. You can change the headers and code for building the rows to return whatever is available for the weather station you’re interested in. This one grabs a few days of data for Peking.

Jamie Bull |

Related Posts

WiGLE is a popular platform which can be used for finding the location of a device using the names of WiFi networks in its vicinity. I’ve written about this before, and wrote some Python code to interact with their API. This API has since been retired and replaced with a new one, as of December […]

Just a quick post to point out a couple of really useful tools.The first is a web-based tool for finding weather files for a location of interest. It’s similar to the Excel EPW finder tool we created a few years back, but much more modern looking. It is however missing a few of the useful […]

Eppy is a really useful library which I’ve written about several times, since before I really had anything to offer in terms of contributing code. Over the past year or so though, I’ve started to contribute back some of the changes and additions I’ve made while using eppy on academic and commercial projects.This post is […]

15 Comments on “Wunderground data to CSV”

  • e says:

    Which version of python is this for?


  • sb says:

    Hi, can be adapted the script to can export the data in 1 csv file for all the stations and to have the station_ids included on each day ?

  • sb says:

    would you give me an ensign where should I start ? I would really appreciate your help.

    Thank you.

    • Jamie Bull says:

      Just think about how you would do it by hand, step by step. How do you want the data to be structured?

      The main thing is that you need to initialise your CSV file outside the main loop, so wove the with open... line above the for station_id in station_ids: line and fix the indentation.

      And then when you write each row you want to add the station ID. So after row = [] you want the next line to be row.append(station_id).

      That should be all you need to do.

      • sb says:

        same structure but after date to include the station, so in case we use multiple stations to know for what entry is each one.

        ultimately this format will be written into a table in db so to can plot.
        looking to look like bellow row.

        date | station_id | tempm | wspdm

        Thank you,

        • Jamie Bull says:

          Ok, so like I said above but with that row.append(station_id) being one line lower

          • sb says:


            One more quick question: I do try to change for geolookup feature but getting error for geolokup in for location in data['geolookup']['location']: any sugestion what can be wrong ? Can you help me please?

  • Jamie Bull says:

    What error message are you getting? I notice you’ve removed the error handling.

  • DougIvey says:

    Hey Jamie,
    is it posible to set the start day ,to for example, to 2016.01.27 1am. Or can wunderground only work with days not with hours?
    I want to get the data from one day between hour x and hour y.

    Thanks for your help

    • Jamie Bull says:

      As far as I’m aware the API is only for entire days. It’s simple enough to grab that and then throw away what you don’t need though.

Leave a Reply

Your email address will not be published. Required fields are marked *