Climate Change Data Analysis Project in Python

Data Science project 19

Climate Change Data Analysis Project in Python

Build a complete climate change data analysis workflow with reproducible Python code, traceable calculations, validation checks, and honest limitations.

Explore Data Science training in VizagView all project ideas

Analysis question

How are a linear per-decade change, goodness of fit, fitted trend, and centred five-year moving average calculated?

Dataset

A synthetic annual temperature-anomaly series from 1980 through 2025 with a seeded trend, periodic variation, and noise.

Requirements

  • Python 3.10 or later
  • A terminal or command prompt
  • python -m pip install numpy pandas scikit-learn
  • About 45-60 minutes to build and review

Method and data checks

Sort annual observations, fit a simple linear regression on year, convert the annual coefficient to change per decade, predict the fitted trend, and calculate a centred moving average.

  • The series is labelled synthetic wherever results appear
  • Years are ordered before fitting and smoothing
  • The per-decade coefficient is calculated from the annual slope
  • No synthetic estimate is presented as observed climate evidence

Complete Python code

Save the program as ds_climate_change_analysis.py. The dataset generator or loader, analysis functions, output, and reproducibility controls are included.

"""Trend-analysis mechanics using synthetic temperature anomalies."""

from __future__ import annotations

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression


def make_demo_anomalies(start: int = 1980, end: int = 2025, seed: int = 42) -> pd.DataFrame:
    rng = np.random.default_rng(seed)
    years = np.arange(start, end + 1)
    anomaly = -0.2 + 0.021 * (years - start) + 0.08 * np.sin(2 * np.pi * (years - start) / 9) + rng.normal(0, 0.06, len(years))
    return pd.DataFrame({"year": years, "temperature_anomaly_c": anomaly})


def analyse_trend(data: pd.DataFrame) -> tuple[dict[str, float], pd.DataFrame]:
    climate = data.copy().sort_values("year")
    model = LinearRegression().fit(climate[["year"]], climate["temperature_anomaly_c"])
    climate["trend"] = model.predict(climate[["year"]])
    climate["moving_average_5y"] = climate["temperature_anomaly_c"].rolling(5, center=True).mean()
    metrics = {"linear_change_per_decade_c": float(model.coef_[0] * 10), "r_squared": float(model.score(climate[["year"]], climate["temperature_anomaly_c"])), "years": float(len(climate))}
    return metrics, climate


def main() -> None:
    metrics, data = analyse_trend(make_demo_anomalies())
    print({k: round(v, 4) for k, v in metrics.items()})
    print(data.tail(8).round(3).to_string(index=False))
    print("Synthetic anomalies teach trend calculations; they are not observed climate evidence.")


if __name__ == "__main__":
    main()

Run the project

  1. Create and activate a virtual environment.
  2. Install dependencies with python -m pip install numpy pandas scikit-learn.
  3. Run python ds_climate_change_analysis.py.
  4. Reconcile row counts and totals before interpreting patterns.
  5. Read the limitations before substituting any real dataset.

Expected analytical output

Linear change per decade, R-squared, row count, fitted trend, and five-year moving-average columns.

Interpretation and responsible-use limits

These generated anomalies teach calculations only and are not observed climate evidence. Real climate conclusions require authoritative datasets, baseline definitions, coverage methods, uncertainty, and domain review.

Ways to extend the project

Load an authoritative global or regional series, cite version and baseline, preserve uncertainty, compare robust trend methods, inspect autocorrelation, and distinguish weather from climate.

Continue learning Data Science

Try the next project, return to the Softenant project library, or explore the Data Science course in Vizag for guided data cleaning, analysis, visualisation, and portfolio feedback.