The objective of this paper is to analyse the local (Montreal in my case) and the global temperature data and compare the temperature trends.
# Import all the packages needed for my analysis
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
# Load data
df=pd.read_csv(r'C:/Users/HP/Documents/UDACITY/PROJECT1/results.csv', index_col='year')
#print first five rows of the dataset
df.head()
#print Last two rows of the dataset
df.tail(2)
# View dimensions of dataset-Number of rows and columns
df.shape
This weather dataset provides information about the temperature for the world as well as for Montreal, between 1750 and 2013.
# A concise summary of the dataframe,including the number of non-null values in each column
df.info()
#count total rows in each column which contain null values
df.isnull().sum()
#count total rows in each column which contain null values
df.isin([0]).sum()
# print descriptive statistics for each column of data
df.describe()
Overall, it appears that Montreal is cooler on average compared to the global average. Indeed, the average temperature in Montreal, between 1750 and 2013, was 4.44 °C compared to 8.36 °C for the global average temperature.
#correlation between the two variables
df[['local temp','global temp']].corr()
The temperature data in Montreal and in the world are highly and positively correlated, with a correlation coefficient of 0.72 and have the same trend (see figure below) .
#calculate 10 years moving average and plot
df['Global temp moving average 10']=df['global temp'].rolling(window=10).mean()
df['Local temp moving average 10']=df['local temp'].rolling(window=10).mean()
#plot the two calculated moving average
df['Local temp moving average 10'].plot(figsize=(12,6))
df['Global temp moving average 10'].plot(figsize=(12,6))
plt.title("Figure 1: Evolution of the local and global temperature trends (Moving average 10 years)")
plt.ylabel('Temperature°C')
plt.legend();
An upward trend has been observed both in Montreal and globally, and has intensified in recent years, most notably in Montreal with a temperature peak of 7.86 °C in 2013 compared to an average of 5.01 °C between 1900 and 2013, and the global temperature increased to 9.61 °C in 2013 compared to an average of 8.75 °C between 1900 and 2013.
As a conclusion the world is getting hotter, and the rate of warming in Montreal is going faster. Indeed, the temperature in Montreal has risen by 3.20 °C between 1900 and 2013, about triple the global rate (increase of 1.11°C over this same period).