Project 2: Holiday weather

by RJ Weise, October 30th 2015

This is the project notebook for Week 2 of The Open University's Learn to code for Data Analysis course.

There is nothing I like better than taking a holiday. In the winter I like to have a two week break in a country where I can be guaranteed sunny dry days. In the summer I like to have two weeks off relaxing in my garden in Calgary. However I'm often disappointed because I pick a fortnight when the weather is dull and it rains. So in this project I am going to use the historic weather data from the Weather Underground for Calgary to try to predict two good weather weeks to take off as holiday next summer. Of course the weather in the summer of 2016 may be very different to 2014 but it should give me some indication of when would be a good time to take a summer break.

Getting the data

From http://www.wunderground.com/history I got weather data for Calgary for the time period From: 1 January 2014 to: 31 December 2014 and then click on 'Get History'. The data for that year should then be displayed. Scroll to the end of the data and then right click on the blue link labelled 'Comma Delimited File':

  • if you are using the Safari Browser choose Download Linked File As ...
  • if you are using the Chrome Browser choose Save Link As ...

then, in the File dialogue that appears save the file with its default name of 'CustomHistory' to the folder you created for this course and where this notebook is located. Once the file has been downloaded rename it from 'CustomHistory.html' to 'London_2014.csv'.

Now load the CSV file into a dataframe making sure that any extra spaces are skipped:

In [21]:
from pandas import *
yyc = read_csv('Calgary.csv', skipinitialspace=True)

Cleaning the data

First we need to clean up the data. I'm not going to make use of 'WindDirDegrees' in my analysis, but you might in yours so we'll rename 'WindDirDegrees< br />' to 'WindDirDegrees'.

In [7]:
yyc = yyc.rename(columns={'WindDirDegrees<br>' : 'WindDirDegrees'})

remove the < br /> html line breaks from the values in the 'WindDirDegrees' column.

In [23]:
#yyc['WindDirDegrees'] = yyc['WindDirDegrees'].str.rstrip('<br>')

and change the values in the 'WindDirDegrees' column to float64:

In [12]:
yyc['WindDirDegrees'] = yyc['WindDirDegrees'].astype('float64')   

We definitely need to change the values in the 'GMT' column into values of the datetime64 date type.

In [13]:
yyc['MST'] = to_datetime(yyc['MST'])

We also need to change the index from the default to the datetime64 values in the 'GMT' column so that it is easier to pull out rows between particular dates and display more meaningful graphs:

In [14]:
yyc.index = yyc['MST']

Finding a summer break

According to meteorologists, summer extends for the whole months of June, July, and August in the northern hemisphere and the whole months of December, January, and February in the southern hemisphere. So as I'm in the northern hemisphere I'm going to create a dataframe that holds just those months using the datetime index, like this:

In [15]:
summer = yyc.ix[datetime(2014,6,1) : datetime(2014,8,31)]

I now look for the days with warm temperatures.

In [16]:
summer[summer['Mean TemperatureC'] >= 25]
Out[16]:
MST Max TemperatureC Mean TemperatureC Min TemperatureC Dew PointC MeanDew PointC Min DewpointC Max Humidity Mean Humidity Min Humidity ... Max VisibilityKm Mean VisibilityKm Min VisibilitykM Max Wind SpeedKm/h Mean Wind SpeedKm/h Max Gust SpeedKm/h Precipitationmm CloudCover Events WindDirDegrees
MST

0 rows × 23 columns

Summer 2014 was rather cool in London: there are no days with temperatures of 25 Celsius or higher. Best to see a graph of the temperature and look for the warmest period.

So next we tell Jupyter to display any graph created inside this notebook:

In [17]:
%matplotlib inline

Now let's plot the 'Mean TemperatureC' for the summer:

In [18]:
summer['Mean TemperatureC'].plot(grid=True, figsize=(10,5))
Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4965fdd550>
In [ ]:
 

Well looking at the graph the last week of July looks good for mean temperatures over 20 degrees C so let's also put precipitation on the graph too:

In [19]:
summer[['Mean TemperatureC', 'Precipitationmm']].plot(grid=True, figsize=(10,5))
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4963d13c50>

The whole month of July is looking good, with a few peaks of rain. Lets have a closer look by just plotting mean temperature and precipitation for July.

In [20]:
july = summer.ix[datetime(2014,7,1) : datetime(2014,7,31)]
july[['Mean TemperatureC', 'Precipitationmm']].plot(grid=True, figsize=(10,5))
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4963b61e10>

The first two weeks of July look good here, stable temperature between 17 and 21, and hardly any rain.

Conclusions

The graphs have shown the first two weeks of July will be dry and fairly warm in Calgary.

In [ ]: