The objective of this paper is to analyse the local (Montreal in my case) and the global temperature data and compare the temperature trends.

In [1]:
# Import all the packages needed for my analysis
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
# 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()
Out[2]:
local temp global temp
year
1750 5.00 8.72
1751 5.62 7.98
1752 -3.22 5.78
1753 4.44 8.39
1754 4.54 8.47
In [3]:
#print Last two rows of the dataset
df.tail(2)
Out[3]:
local temp global temp
year
2012 7.09 9.51
2013 7.86 9.61
In [4]:
# View dimensions of dataset-Number of rows and columns
df.shape
Out[4]:
(264, 2)

This weather dataset provides information about the temperature for the world as well as for Montreal, between 1750 and 2013.

In [5]:
#  A concise summary of the dataframe,including the number of non-null values in each column
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 264 entries, 1750 to 2013
Data columns (total 2 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   local temp   264 non-null    float64
 1   global temp  264 non-null    float64
dtypes: float64(2)
memory usage: 6.2 KB
In [6]:
#count total rows in each column which contain null values
df.isnull().sum()
Out[6]:
local temp     0
global temp    0
dtype: int64
In [7]:
#count total rows in each column which contain null values
df.isin([0]).sum()
Out[7]:
local temp     0
global temp    0
dtype: int64
In [8]:
# print descriptive statistics for each column of data
df.describe()
Out[8]:
local temp global temp
count 264.000000 264.000000
mean 4.440455 8.359394
std 1.069468 0.575184
min -3.220000 5.780000
25% 3.860000 8.077500
50% 4.420000 8.365000
75% 5.040000 8.700000
max 7.860000 9.730000

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.

In [9]:
#correlation between the two variables
df[['local temp','global temp']].corr()
Out[9]:
local temp global temp
local temp 1.000000 0.721534
global temp 0.721534 1.000000

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) .

In [10]:
#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.

Conclusion

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).

In [ ]: