by Rob Griffiths and Kate Williams, 21 August 2016
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 Cardiff, Wales. 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 Cardiff 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 2015 but it should give me some indication of when would be a good time to take a summer break.
You can obtain the data as follows. Right-click on the following URL and choose 'Open Link in New Window' (or similar, depending on your browser):
http://www.wunderground.com/history
When the new page opens start typing 'Cardiff' in the 'Location' input box and when the pop up menu comes up with the option 'Cardiff, United Kingdom' select it and then click on 'Submit'.
When the next page opens click on the 'Custom' tab and selet the time period From: 1 January 2015 to: 31 December 2015 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':
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 'MyLocation_2015.csv'.
Now load the CSV file into a dataframe making sure that any extra spaces are skipped:
import warnings
warnings.simplefilter('ignore', FutureWarning)
from pandas import *
cardiff = read_csv('MyLocation_2015.csv', skipinitialspace=True)
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'.
cardiff = cardiff.rename(columns={'WindDirDegrees<br />' : 'WindDirDegrees'})
remove the < br /> html line breaks from the values in the 'WindDirDegrees' column.
cardiff['WindDirDegrees'] = cardiff['WindDirDegrees'].str.rstrip('<br />')
and change the values in the 'WindDirDegrees' column to float64:
cardiff['WindDirDegrees'].astype('float64')
We definitely need to change the values in the 'GMT' column into values of the datetime64 date type.
cardiff['GMT'] = to_datetime(cardiff['GMT'])
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:
cardiff.index = cardiff['GMT']
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:
summer = cardiff.ix[datetime(2015,6,1) : datetime(2015,8,31)]
I now look for the days with warm temperatures.
summer[summer['Max TemperatureC'] >= 25]
Summer 2015 was quite cool in Cardiff as there were only 2 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:
%matplotlib inline
Now let's plot the 'Mean TemperatureC' for the summer:
summer['Mean TemperatureC'].plot(grid=True, figsize=(10,5))
Looking at the graph the end of June looks good for mean temperatures over 20 degrees C. Unfortunately there is no percipitation data avialable for Cardiff so we are not able to compare mean temperatures to percipitation levels.
The graphs have shown the volatility of a British summer,although the lack of percipitation data prevents a thorough analysis. To make a sensible prediction we would need to analyse the summers for many more years witht the inclusion of percipitation data.