Is Philadelphia getting hotter?

Serdar
2 min readJun 3, 2021

Full disclosure: As I have recently started working on the Udacity Data Analyst Nanodegree, I wanted to share the findings of my first of many projects on the horizon. Please do judge based on that.. Please do share your comments and suggestions so I can improve.

In this article, I will share the temperature time series data, dating back to 1743 and up until 2013 for Philadelphia in comparison with the global temperature changes. My methodology will be to use 7 year moving average which is commonly used while analyzing the time series data.

The tools I have used to create this project are ;

Pycharm IDE, Pandas, Matploblib libraries and Sql

For data extraction from the database I used the below query. Since the data was already in a granular view, all I needed to do is to extract the data related to the city.

select * from city_data where city = ‘Philadelphia’

In order to compare the local changes with the global data, I also downloaded the second dataset using the query below;

select * from global_data

To calculate the moving averages I have applied the rolling().mean() chain method. What rolling function does is that it sets the timeframe we want to offset. In our example, we want to calculate the 7-year moving average so I set the window = 7. In order to calculate the average we added the mean() method at the end of the method.

df['7-year MA'] = df.avg_temp.rolling(window=7).mean()
df_global['7-year MA Globe'] = df_global.avg_temp.rolling(window=7).mean()

Creating the plot

This part was the most complicated for me since this is my first time using the matplotlib library. Below code shows setting the year as index, defining the trendline colors and the labeling;

df.set_index('year')['7-year MA'].plot(ax=ax,
color='r',
label="Philadephia 7 Year Moving Average")

df_global.set_index('year')['7-year MA Globe'].plot(ax=ax,
color='b',
label="Global 7 Year Moving Average")

Observations

As below graph displays that over the course of the last 270 years, Philadelphia region has been hotter then average globe. Despite some disruptions in the data around late 1700s, the trend was mostly downwards. Around 1818, it was the coolest time frame, where both Philadelphia and the rest of the globe having the same trend. Since then it was mostly upwards and the trendline continues to be upwards for the earth.

--

--