Contents

Callysto.ca Banner

Open in Callysto

Monthly Climate Data

We can get temperature and precipitation data averaged by month for 1901 to 2016 from World Bank Climate Change Knowledge Portal. You will need the latitude and longitude of a location from a site such as latlong.net.

latitude = 43.7521
longitude = -79.7614

import pandas as pd
temperature_url = 'https://climateknowledgeportal.worldbank.org/api/data/get-download-data/historical/tas/1901-2016/'+str(latitude)+'$cckp$'+str(longitude)+'/'+str(latitude)+'$cckp$'+str(longitude)
temperature_all = pd.read_csv(temperature_url)
temperature = temperature_all.replace(' Average','',regex=True).replace(' ','',regex=True).rename(columns={'Temperature - (Celsius)':'Temperature (°C)', ' Statistics':'Month'})
precipitation_url = 'https://climateknowledgeportal.worldbank.org/api/data/get-download-data/historical/pr/1901-2016/'+str(latitude)+'$cckp$'+str(longitude)+'/'+str(latitude)+'$cckp$'+str(longitude)
precipitation_all = pd.read_csv(precipitation_url)
precipitation = precipitation_all.replace(' Average','',regex=True).replace(' ','',regex=True).rename(columns={'Rainfall - (MM)':'Precipitation (mm)', ' Statistics':'Month'})
climate = pd.merge(temperature, precipitation).drop(columns=[' Longitude',' Latitude'])
climate
Temperature (°C) Year Month Precipitation (mm)
0 -6.300000 1901 Jan 44.600002
1 -9.900001 1901 Feb 56.900002
2 -2.700000 1901 Mar 57.600002
3 6.700000 1901 Apr 56.799999
4 11.900001 1901 May 80.300003
... ... ... ... ...
1387 22.400000 2016 Aug 112.900002
1388 17.600000 2016 Sep 79.900002
1389 10.500000 2016 Oct 105.700005
1390 5.700000 2016 Nov 60.799999
1391 -3.200000 2016 Dec 68.300003

1392 rows × 4 columns

Callysto.ca License