├── file1 ├── file3 ├── file2 └── README.md /file1: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import matplotlib.pyplot as plt 3 | import seaborn as sns 4 | from sklearn.linear_model import LinearRegression 5 | import numpy as np 6 | 7 | # Load your dataset (e.g., NASA GISTEMP global temperature anomalies) 8 | # Sample CSV format: columns = ['Year', 'Anomaly'] 9 | def load_data(filepath): 10 | df = pd.read_csv(filepath) 11 | df = df[['Year', 'Anomaly']] 12 | df.dropna(inplace=True) 13 | return df 14 | 15 | # Analyze trend using linear regression 16 | def analyze_trend(df): 17 | X = df['Year'].values.reshape(-1, 1) 18 | y = df['Anomaly'].values.reshape(-1, 1) 19 | 20 | model = LinearRegression() 21 | model.fit(X, y) 22 | df['Trend'] = model.predict(X) 23 | 24 | slope = model.coef_[0][0] 25 | intercept = model.intercept_[0] 26 | print(f"Linear Trend: Anomaly = {slope:.5f} * Year + {intercept:.2f}") 27 | 28 | return df, slope, intercept 29 | 30 | # Visualize trend 31 | def plot_trend(df): 32 | plt.figure(figsize=(12, 6)) 33 | sns.lineplot(x='Year', y='Anomaly', data=df, label='Observed Anomaly', marker='o') 34 | sns.lineplot(x='Year', y='Trend', data=df, label='Trend Line', color='red') 35 | plt.title('Global Temperature Anomalies Over Time') 36 | plt.xlabel('Year') 37 | plt.ylabel('Temperature Anomaly (°C)') 38 | plt.legend() 39 | plt.grid(True) 40 | plt.tight_layout() 41 | plt.show() 42 | 43 | # Main 44 | if __name__ == "__main__": 45 | filepath = 'global_temp_anomaly.csv' # Replace with your file path 46 | df = load_data(filepath) 47 | df, slope, intercept = analyze_trend(df) 48 | plot_trend(df) 49 | -------------------------------------------------------------------------------- /file3: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import matplotlib.pyplot as plt 3 | import seaborn as sns 4 | from sklearn.linear_model import LinearRegression 5 | 6 | def load_data(filepath, columns): 7 | df = pd.read_csv(filepath) 8 | df = df[columns] 9 | df.dropna(inplace=True) 10 | return df 11 | 12 | def analyze_trend(df, x_col, y_col): 13 | X = df[[x_col]].values 14 | y = df[[y_col]].values 15 | 16 | model = LinearRegression() 17 | model.fit(X, y) 18 | df['Trend'] = model.predict(X) 19 | 20 | slope = model.coef_[0][0] 21 | intercept = model.intercept_[0] 22 | print(f"Linear Trend for {y_col}: {y_col} = {slope:.5f} * {x_col} + {intercept:.2f}") 23 | 24 | return df, slope, intercept 25 | 26 | def plot_trend(df, x_col, y_col, title, ylabel): 27 | plt.figure(figsize=(12, 6)) 28 | sns.lineplot(x=x_col, y=y_col, data=df, label='Observed', marker='o') 29 | sns.lineplot(x=x_col, y='Trend', data=df, label='Trend Line', color='red') 30 | plt.title(title) 31 | plt.xlabel(x_col) 32 | plt.ylabel(ylabel) 33 | plt.legend() 34 | plt.grid(True) 35 | plt.tight_layout() 36 | plt.show() 37 | 38 | def main(): 39 | # Example for regional temperature anomalies 40 | temp_df = load_data('regional_temp_anomaly.csv', ['Year', 'Region', 'Anomaly']) 41 | region = 'Africa' # Specify the region of interest 42 | temp_region_df = temp_df[temp_df['Region'] == region] 43 | temp_region_df, temp_slope, temp_intercept = analyze_trend(temp_region_df, 'Year', 'Anomaly') 44 | plot_trend(temp_region_df, 'Year', 'Anomaly', f'{region} Temperature Anomalies Over Time', 'Temperature Anomaly (°C)') 45 | 46 | # Similarly, implement for other indicators and regions 47 | 48 | if __name__ == "__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /file2: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import matplotlib.pyplot as plt 3 | import seaborn as sns 4 | from sklearn.linear_model import LinearRegression 5 | import numpy as np 6 | 7 | def load_data(filepath, columns): 8 | df = pd.read_csv(filepath) 9 | df = df[columns] 10 | df.dropna(inplace=True) 11 | return df 12 | 13 | def analyze_trend(df, x_col, y_col): 14 | X = df[[x_col]].values 15 | y = df[[y_col]].values 16 | 17 | model = LinearRegression() 18 | model.fit(X, y) 19 | df['Trend'] = model.predict(X) 20 | 21 | slope = model.coef_[0][0] 22 | intercept = model.intercept_[0] 23 | print(f"Linear Trend for {y_col}: {y_col} = {slope:.5f} * {x_col} + {intercept:.2f}") 24 | 25 | return df, slope, intercept 26 | 27 | def plot_trend(df, x_col, y_col, title, ylabel): 28 | plt.figure(figsize=(12, 6)) 29 | sns.lineplot(x=x_col, y=y_col, data=df, label='Observed', marker='o') 30 | sns.lineplot(x=x_col, y='Trend', data=df, label='Trend Line', color='red') 31 | plt.title(title) 32 | plt.xlabel(x_col) 33 | plt.ylabel(ylabel) 34 | plt.legend() 35 | plt.grid(True) 36 | plt.tight_layout() 37 | plt.show() 38 | 39 | def main(): 40 | # Temperature Anomalies 41 | temp_df = load_data('global_temp_anomaly.csv', ['Year', 'Anomaly']) 42 | temp_df, temp_slope, temp_intercept = analyze_trend(temp_df, 'Year', 'Anomaly') 43 | plot_trend(temp_df, 'Year', 'Anomaly', 'Global Temperature Anomalies Over Time', 'Temperature Anomaly (°C)') 44 | 45 | # CO2 Emissions 46 | co2_df = load_data('co2_emissions.csv', ['Year', 'CO2']) 47 | co2_df, co2_slope, co2_intercept = analyze_trend(co2_df, 'Year', 'CO2') 48 | plot_trend(co2_df, 'Year', 'CO2', 'Global CO₂ Emissions Over Time', 'CO₂ Emissions (Gt)') 49 | 50 | # Sea Level Rise 51 | sea_df = load_data('sea_level.csv', ['Year', 'Sea_Level']) 52 | sea_df, sea_slope, sea_intercept = analyze_trend(sea_df, 'Year', 'Sea_Level') 53 | plot_trend(sea_df, 'Year', 'Sea_Level', 'Global Sea Level Rise Over Time', 'Sea Level Change (mm)') 54 | 55 | if __name__ == "__main__": 56 | main() 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 🌍 Climate Change Trend Analyzer 2 | 3 | Climate Change Trend Analyzer is a Python-based tool designed to analyze and visualize trends in global climate indicators, including temperature anomalies, CO₂ emissions, and sea level rise. By leveraging linear regression and data visualization techniques, this tool aids researchers, educators, and policymakers in understanding the progression of climate change over time. 4 | 📊 Features 5 | 6 | Trend Analysis: Applies linear regression to identify trends in climate data. 7 | 8 | Visualization: Generates line charts to depict observed data alongside trend lines. 9 | 10 | Modular Design: Structured codebase for easy extension and maintenance. 11 | 12 | Data Flexibility: Compatible with various datasets in CSV format. 13 | 14 | 📁 Project Structure 15 | 16 | Climate-Change-Trend-Analyzer/ 17 | ├── data/ 18 | │ ├── global_temp_anomaly.csv 19 | │ ├── co2_emissions.csv 20 | │ └── sea_level.csv 21 | ├── analyzer.py 22 | ├── requirements.txt 23 | └── README.md 24 | 25 | data/: Contains the CSV files with climate data. 26 | 27 | analyzer.py: Main script for data analysis and visualization. 28 | 29 | requirements.txt: Lists the Python dependencies. 30 | 31 | README.md: Project documentation. 32 | 33 | 🛠️ Installation 34 | 35 | Clone the Repository 36 | 37 | git clone https://github.com/yourusername/Climate-Change-Trend-Analyzer.git 38 | cd Climate-Change-Trend-Analyzer 39 | 40 | Create a Virtual Environment (Optional but Recommended) 41 | 42 | python -m venv venv 43 | source venv/bin/activate # On Windows: venv\Scripts\activate 44 | 45 | Install Dependencies 46 | 47 | pip install -r requirements.txt 48 | 49 | 📈 Usage 50 | 51 | Prepare Your Data 52 | 53 | Ensure your CSV files are formatted as follows: 54 | 55 | Temperature Anomalies (global_temp_anomaly.csv) 56 | 57 | Year,Anomaly 58 | 1880,-0.12 59 | 1881,-0.10 60 | ... 61 | 2023,1.10 62 | 63 | CO₂ Emissions (co2_emissions.csv) 64 | 65 | Year,CO2 66 | 1960,9.4 67 | 1961,9.6 68 | ... 69 | 2023,36.8 70 | 71 | Sea Level Rise (sea_level.csv) 72 | 73 | Year,Sea_Level 74 | 1993,0.0 75 | 1994,0.3 76 | ... 77 | 2023,9.2 78 | 79 | Run the Analyzer 80 | 81 | python analyzer.py 82 | 83 | The script will: 84 | 85 | Load each dataset. 86 | 87 | Perform linear regression to identify trends. 88 | 89 | Display line charts with observed data and trend lines. 90 | 91 | Output the linear trend equations to the console. 92 | 93 | 📦 Dependencies 94 | 95 | Python 3.6 or higher 96 | 97 | pandas 98 | 99 | matplotlib 100 | 101 | seaborn 102 | 103 | scikit-learn 104 | 105 | Install all dependencies using: 106 | 107 | pip install -r requirements.txt 108 | 109 | 📚 Data Sources 110 | 111 | Temperature Anomalies: NASA GISTEMP 112 | 113 | CO₂ Emissions: Our World in Data 114 | 115 | Sea Level Rise: NOAA Sea Level Trends 116 | 117 | 🤝 Contributing 118 | 119 | Contributions are welcome! Please fork the repository and submit a pull request with your enhancements. 120 | 📄 License 121 | 122 | This project is licensed under the MIT License. See the LICENSE file for details. 123 | --------------------------------------------------------------------------------