Monthly Mean Weather Data

I’m creating some climate data graphs for an extension project I’m working on and need a way to directly access monthly mean temperature data for a given location. I wrote a Python script as a hacky way to do it. The script is up on GitHub.

Basically, the script uses urllib to query Weather Underground for historical data for a given weather station over a given range of years. When you execute the script, it will ask you for the following:

  1. A 4-letter ICAO airport code. Wikipedia has a list of airport codes for the contiguous United States, Alaska, and Hawaii. Note that Weather Underground may not have data for all of the stations. I haven’t found any where they don’t, but I haven’t exhaustively tested, either
  2. A starting year. The Weather Underground database goes from 1948–present, although there may be missing months or years for some stations.
  3. An ending year. This can be the same as the starting year. If your ending year is earlier than your starting year, the script will execute but nothing will happen.

Once you enter a station, starting, and ending year, the script will create a data directory (assuming it doesn’t already exist) and create a file called historicalMonthlyMeans_STATION_STARTYEAR-ENDYEAR.csv. The csv will have the year, month, station, and mean temperature for the years that you entered.

Note that the script is slow since it runs each query one after another. Patience remains a virtue.