Analyzing Global Temperature Anomalies and CO2 Concentrations
Introduction
In this coding colab, youβll analyze global temperature anomalies and CO2 concentration data. Youβll practice data manipulation, joining datasets, time series analysis, and visualization techniques.
Learning Objectives
By the end of this colab, you will be able to:
Load and preprocess time series data
Join datasets based on datetime indices
Perform basic time series analysis and resampling
Apply data manipulation techniques to extract insights from environmental datasets
Setup
Letβs start by importing necessary libraries and loading our datasets:
Code
import pandas as pdimport matplotlib.pyplot as pltimport seaborn as sns# Load the temperature anomaly datasettemp_url ="https://bit.ly/monthly_temp"temp_df = pd.read_csv(temp_url, parse_dates=['Date'])# Load the CO2 concentration datasetco2_url ="https://bit.ly/monthly_CO2"co2_df = pd.read_csv(co2_url, parse_dates=['Date'])print("Temperature data:")print(temp_df.head())print("\nCO2 data:")print(co2_df.head())
Temperature data:
Date MonthlyAnomaly
0 1880-01-01 -0.20
1 1880-02-01 -0.25
2 1880-03-01 -0.09
3 1880-04-01 -0.16
4 1880-05-01 -0.09
CO2 data:
Date CO2Concentration
0 1958-04-01 317.45
1 1958-05-01 317.51
2 1958-06-01 317.27
3 1958-07-01 315.87
4 1958-08-01 314.93
Task 1: Data Preparation
Set the βDateβ column as the index for both dataframes.
Ensure that there are no missing values in either dataset.
Task 2: Joining Datasets
Merge the temperature and CO2 datasets based on their date index.
Handle any missing values that may have been introduced by the merge.
Create some plots showing temperature anomalies and CO2 concentrations over time using pandas built-in plotting functions.
Task 3: Time Series Analysis
Resample the data to annual averages.
Calculate the year-over-year change in temperature anomalies and CO2 concentrations.
Create a scatter plot (use the plt.scatter() function) of annual temperature anomalies vs CO2 concentrations.
Task 4: Seasonal Analysis
Create a function to extract the season from a given date (hint: use the date.month attribute and if-elif-else to assign the season in your function).
Use the function to create a new column called Season
Calculate the average temperature anomaly and CO2 concentration for each season.
Create a box plot (use sns.boxplot) showing the distribution of temperature anomalies for each season.