Global surface temperature change

The following data is based on the Berkeley Earth all land monthly average temperature dataset. Absolute temperatures are provided in addition to normalized temperatures with base period 1951-1980.

For more, please refer to the original website.


In [3]:
import pandas as pd
import calendar

URL = "http://berkeleyearth.lbl.gov/auto/Global/Complete_TAVG_complete.txt"
COLUMNS = ["year", "month_idx", "temp_anomaly"]
MONTH_MAPPING = {idx: abbr for idx, abbr in enumerate(calendar.month_abbr)}
BASE_TEMP = { 1: 2.62,   2: 3.23,   3: 5.33,
              4: 8.36,   5: 11.37,  6: 13.53,
              7: 14.41,  8: 13.93,  9: 12.12,
             10: 9.26,  11: 6.12,  12: 3.67}

def fetch_global_temperatures(file):
    df = pd.read_csv(URL, skiprows=34, header=None, delim_whitespace=True, 
                     usecols=range(3), names=COLUMNS)
    
    # get absolute temperature by anomaly + base values
    df["temp_absolute"] = df["month_idx"].map(BASE_TEMP) + df["temp_anomaly"]
    
    # add month names
    df["month"] = df["month_idx"].map(MONTH_MAPPING)
    
    df.to_csv(file, index=False)