by Rob Griffiths and Suzanne Lees, 11 September 2015, updated 11 April 2017, 18 October 2017, 20 December 2017, and 6 August 2017
This is the project notebook for the second part 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 London. 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 London 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.
Weather Underground keeps historical weather data collected in many airports around the world. Right-click on the following URL and choose 'Open Link in New Window' (or similar, depending on your browser):
When the new page opens start typing 'LHR' in the 'Location' input box and when the pop up menu comes up with the option 'LHR, United Kingdom' select it and then click on 'Submit'.
When the next page opens with London Heathrow data, click on the 'Custom' tab and select 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 further down the page.
You can copy each month's data directly from the browser to a text editor like Notepad or TextEdit, to obtain a single file with as many months as you wish.
Weather Underground has changed in the past the way it provides data and may do so again in the future.
I have therefore collated the whole 2014 data in the provided 'London_2014.csv' file.
Now load the CSV file into a dataframe making sure that any extra spaces are skipped:
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:
The graphs have shown the volatility of a British summer, but a couple of weeks were found when the weather wasn't too bad in 2014. Of course this is no guarantee that the weather pattern will repeat itself in future years. To make a sensible prediction we would need to analyse the summers for many more years. By the time you have finished this course you should be able to do that.
For my ideal holiday, I would have little rain, low humidity, high visibility, and temperatures between 20 and 25 degrees C. The temperature condition was satisfied for the 32 dates above. I will now disregard any of these 32 dates for which there was rain.
<matplotlib.axes._subplots.AxesSubplot at 0x7f7bcd3470b8>
The graph looks misleading because the values for humidity are much higher than those for visibility and temperature. In an attempt to combat this, I will scale the humidity down.
temperature=temp['Mean TemperatureC']humidity=temp['Mean Humidity']humidity=(temperature.mean()*humidity)/humidity.mean()temp['Scaled Mean Humidity']=humiditytemp[['Mean TemperatureC','Scaled Mean Humidity','Mean VisibilityKm']].plot(grid=True,figsize=(10,5))
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
<matplotlib.axes._subplots.AxesSubplot at 0x7f7bcc47ee10>
Now it appears that the visibility does not vary by enough for it to impact my decision. I wish to choose the 2 week period with most temperatures in my chosen range and low humidity. It looks like the end of July/beginning of August is the best. I will restrict my consideration to the time period 15th July to 15th August. I will now show the maximum and minimum humidity and temperature.
temp=temp.loc[datetime(2014,7,15):datetime(2014,8,15)]temperature=temp['Mean TemperatureC']humidity=temp['Mean Humidity']minHumidity=temp['Min Humidity']minHumidity=(temperature.mean()*minHumidity)/humiditymaxHumidity=temp['Max Humidity']maxHumidity=(temperature.mean()*maxHumidity)/humiditytemp['Scaled Min Humidity']=minHumiditytemp['Scaled Max Humidity']=maxHumidity
temp[['Min TemperatureC','Scaled Max Humidity','Scaled Min Humidity','Max TemperatureC','Mean TemperatureC']].plot(grid=True,figsize=(10,5))
<matplotlib.axes._subplots.AxesSubplot at 0x7f7bcc1363c8>
With this amount of variation, it is difficult to choose the best 2 weeks.
Using the data about Moscow, and my personal weather preferences, I have concluded that the best time to visit Moscow is between late July and early August. However, during this time period, humidity and temperature did not vary with enough significance to choose a specific 2 week period.