Skip to main content
Skip to content

About this free course

Download this course

Share this free course

Learn to code for data analysis
Learn to code for data analysis

Start this free course now. Just create an account and sign in. Enrol and complete the course for a free statement of participation or digital badge if available.

Week 4: Cleaning up our act Part 2

1 Loading the weather data

You have learned some more about Python and the pandas module and tried it out on a fairly small dataset. You are now ready to explore a dataset from the Weather Underground.

An image of filter like diagonal strips across various skies such as an orange sunset, a storm and a clear blue sky.
Figure 1

Open the file London_2014.csv and save it in the disk folder or CoCalc project you created in Week 1.

Do not be tempted to open this file with Excel as this application will attempt to localise the data in the file, i.e. use your country’s local data formats, which will make much of what follows rather incomprehensible! You can if you like open the file with a simple text editor, but do not make any changes.

The CSV file can be loaded into a dataframe by executing the following code:

In []:

from pandas import *

london = read_csv('London_2014.csv')

london.head()

Out[]:

First 5 rows of the London dataframe.
Figure 2

Note that the right hand side of the table has been cropped to fit on the page.

In the next section, you’ll find out how to remove rogue spaces.

Important notice for learners outside of the EU

The Weather Underground automatically localises data based on from what country it detects you are accessing the web site. So, for example, if you are accessing the website from the USA wind speeds will be in MPH rather than km/h and temperatures in Fahrenheit rather than Celsius.

In order to change the settings so that the data is in European format you will need to click on the ‘head and shoulders’ icon on the top right of the Weather Underground web page and create a free Weather Underground account.

Once you have created an account, click on the ‘cog’ icon on the top right of the web page. Then:

  • click on the C button to select Celsius
  • click on ‘More Settings’ and select Units: metric
  • click on ‘Save My Preferences’.

Now, when you download the data, temperatures will be in Celsius and wind speeds in km/h etc.