Identical series
Two pairs of Brazilian cities are the same series (step 03). "Campinas" really means the region around São Paulo. It is still the nearest data to where I live, so it stays as my local city.
Udacity · Data Analyst Nanodegree
How much warmer is it where I live, compared with the world? Local and global temperatures from 1854 to 2024, step by step.
Average temperature in 1991–2020 compared with 1854–1900 (the 30-year moving average at 2020, in step 05). Global is the average over land.
01
In this project, I analyze local and global temperature data and compare the temperature trends where I live with global trends. I also include two more cities: Amsterdam, in the Netherlands, and Dublin, in Ireland, both well regarded among tech professionals in Brazil.
The Udacity workspace had a database with three tables:
city_list
city · country
342 rowscity_data
year · city · country · avg_temp
yearly average per city, °Cglobal_data
year · avg_temp
yearly global average, °CThe workspace is not public, so I rebuilt the same tables in SQLite with the original source, Berkeley Earth. That way every query on this page can be run again by anyone.
02
After seeing the schema, I decided to understand the data available by gathering general information, like the different cities and countries.
SELECT COUNT(*) AS rows,
COUNT(DISTINCT city) AS city_names,
COUNT(DISTINCT country) AS countries
FROM city_list;
There are 342 rows but only 329 city names. A first interesting insight is about duplicate names: if we only queried by city, the data could have been mixed up. That is why every query here filters by city and country.
The database has no continent column. In 2024 I added one in Excel with a list of countries by continent and a VLOOKUP, after fixing 18 country names that were spelled differently in the two lists. Now the same step is a merge in Python, and the counts match the original ones.
North and South America are counted together. Asia is the most represented continent; Oceania has only 8 cities.
03
There are 11 Brazilian cities in the database: 7 in the southeast and south, 3 in the northeast and 1 in the north. The Midwest is not represented. Hover a city to see its numbers.
Berkeley Earth does not measure each city. It estimates the temperature on a grid that covers the planet, and each city gets the values of the grid point it is assigned to.
Campinas and Guarulhos share the same point, and so do Colombo and Curitiba. That is why their series are identical, not just similar. In 2024 I explained it by their location; the grid is the real reason.
SELECT a.city, b.city, COUNT(*) AS years
FROM city_data a
JOIN city_data b
ON a.year = b.year AND a.city < b.city
WHERE a.country = 'Brazil'
AND b.country = 'Brazil'
GROUP BY a.city, b.city
HAVING SUM(a.avg_temp = b.avg_temp) = COUNT(*);
Result: Campinas–Guarulhos and Colombo–Curitiba, equal in all 182 years. So the database has 11 Brazilian names but 9 independent series.
04
Before plotting anything, I compared my original Udacity exports with the current Berkeley Earth files. Between 1854 and 2012 they move together (correlation above 0.94 for every series), but three things needed fixing.
Identical series
Two pairs of Brazilian cities are the same series (step 03). "Campinas" really means the region around São Paulo. It is still the nearest data to where I live, so it stays as my local city.
Missing years as zero
In my 2024 spreadsheet, the years without data for Campinas (before 1832 and 1844–1850) were stored as 0. A 0 °C average is impossible for Campinas, so I started the chart in 1854 to leave them out. Now those years are simply left empty, so no calculation can use them by mistake.
Incomplete years
The Udacity data stops partway through 2013, so its 2013 average for Campinas misses the warm months and came out 0.5 °C too low. Now a year only counts if it has all 12 months.
05
For the moving average, I chose a 4-year period because it minimizes the influence of single-year anomalies and is still responsive enough to capture meaningful changes. Try other windows with the slider: very long windows over-smooth the data. The 30-year window has a special use: at 2020 it gives the 1991–2020 average used in the key observations.
The first view shows the temperature itself. Campinas is about 11 °C hotter than the global average, so the lines are far apart and it is hard to see that all of them are rising. Switch to Change since 1854–1900 to compare the trends directly.
-- 4-year moving average, the step I did in Excel in 2024
SELECT year, city, avg_temp,
AVG(avg_temp) OVER (ORDER BY year
ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS ma_4_years
FROM city_data
WHERE city = 'Campinas' AND year >= 1854;
06
The same change, for each of the Brazilian cities in the database, against the global average and the other cities.
07
The main comparison is the average of 1991–2020 against the average of 1854–1900. In the chart of step 05, that is the 30-year moving average at 2020, in the "Change since 1854–1900" view: the 30 years that end in 2020 are exactly 1991–2020, the latest 30 years with data for every series.
Shorter windows end higher, because they only average the most recent and hottest years. With a 20-year window, for example, Campinas reaches +1.32 °C in 2020, and with 4 years, +1.59 °C. The hottest years come from the yearly values, with the moving average off. The buttons set the chart for you.
A reader in Brazil may find this surprising: Brazil is much hotter than the Netherlands, so the numbers may look wrong at first. But being hotter and warming faster are different things. This analysis compares the change in temperature, not its level.
The result is consistent with a global climate pattern known as polar amplification: regions at higher latitudes, closer to the poles, tend to warm more and faster than tropical and subtropical regions, such as Southeast Brazil. The effect is strongest in the Arctic and fades towards the equator (Serreze & Barry, 2011). Amsterdam is at 52°N; Campinas is at 23°S.
Latitude is not the only factor, though. Dublin, even further north (53°N) but on the Atlantic coast, warmed as much as Campinas, likely because the ocean around it warms more slowly than land.
Over the whole period, the four series rose slowly during most of the 20th century and much faster from around 1980. With a 10-year moving average, all of them passed +1.0 °C between 1995 and 2002.
The data also reveals potential health risks from more frequent and severe heatwaves, especially for vulnerable groups such as the elderly and children. The world is getting hotter, locally and globally, and the effects need ongoing efforts to be mitigated.
08