AFRICA'S TRANSITION TO SUSTAINABLE ENERGY: 1990-2021
STRATEGIC INSIGHTS FOR RENEWABLE ENERGY ADOPTION IN AFRICA
OBJECTIVE OVERVIEW
The shift towards renewable energy in African countries from 1990 to 2021 presents both challenges and opportunities. To gain strategic insights for renewable energy adoption in Africa, this analysis will focus on several key areas:
- 🔍 Investment Opportunity Identification: Which African countries show the most promising growth in renewable energy consumption, and what factors contribute to their success? This analysis identifies key drivers such as supportive policy frameworks, innovative financing models, and access to advanced renewable technologies. By understanding these factors, investors and policymakers can allocate resources more effectively to high-potential projects.
- 📈 Strategic Energy Transition Planning: How can historical trends inform the development of effective strategies for accelerating renewable energy adoption across Africa? This includes identifying successful models and technologies that can be replicated or adapted in different contexts. The analysis helps in crafting tailored strategies that consider the unique socio-economic and geographic contexts of different African nations.
- 🌱 Sustainable Development Goal Alignment: How does the progress in renewable energy consumption contribute to African countries' advancement towards SDG 7 (Affordable and Clean Energy)? By examining the relationship between renewable energy growth and SDG 7 targets—such as increasing access to affordable, reliable, sustainable, and modern energy—this analysis provides insights into formulating policies that address energy access, affordability, and sustainability in a holistic manner.
- 🏭 Economic Impact Assessment: What is the correlation between increased renewable energy consumption and economic growth in African countries? This analysis explores how renewable energy adoption influences GDP growth. By quantifying these economic benefits, we can make a compelling case for further investment in renewable energy infrastructure and technologies.
- 🌍 Regional Cooperation Framework: How can we use the disparities and similarities in renewable energy adoption across African countries to foster knowledge sharing and cross-border cooperation? This analysis identifies opportunities for regional energy trade agreements, joint research initiatives, and cross-border infrastructure projects. By promoting collaboration, African nations can achieve more efficient resource allocation and accelerated progress towards a sustainable energy future.
- Policymakers designing energy transition strategies
- Investors seeking high-potential renewable energy projects
- Development partners aligning their support with countries' needs
- Energy companies looking to expand their renewable portfolio in Africa
By addressing these, we can provide valuable insights to:
Ultimately, this analysis will contribute to shaping a more sustainable and energy-secure future for Africa, balancing economic growth with environmental stewardship.
- I. Data Overview and Setup
- A. Data Sources and Metrics
- B. Data Processing
- C. Importing Required Libraries
- D. Loading the Dataset
- II. Exploratory Data Analysis
- A. Descriptive Statistics
-
B.
Renewable Energy Consumption in African Countries 1990-2021
- 1. Progression of Renewable Energy Adoption
- 2. Trends in Renewable Energy Consumption
- 3. Top and Bottom Performers in Renewable Energy Consumption
- 4. Top Improved Countries
- 5. Least Improved Countries
- 6. Average Renewable Energy Growth Rate
-
C.
Comparative Analysis of Renewable Energy and Socio-Economic Indicators
- 1. GDP/Capita vs. Renewable Energy Percentage
- 2. FDI/GDP vs. Renewable Energy Percentage for African Countries 1990-2021
-
D.
SDG 7 Indicators of Renewable Energy Adoption
- 1. Renewable Energy Consumption(% of total final energy consumption)
- 2. Renewable Energy Capacity
- 3. Renewable Energy Investments
- 4. Energy Intensity Level
- 5. Access to Modern Energy Services
- 6. Access to Clean Energy
- III. Detailed Analysis
-
A.
Strategic Energy Transition Planning
- 1. CAGR for Renewable Energy Consumption (1990-2021)
- 2. 5-Year Staggered CAGR for Renewable Energy Consumption (1990-2021)
- 3. Cluster Analysis Based on Average Renewable Energy Consumption
-
B.
Investment Opportunity Identification
- 1. Renewable Energy Consumption(%) vs. CAGR (2021)
- 2. Risk-reward Matrix using FDI/GDP
- 3. Correlation between FDI/GDP and Renewable Energy Consumption
- 4. Correlation between FDI/GDP, CAGR and Renewable Energy Consumption
-
C.
Sustainable Development Goal 7 Alignment
- 1. Correlation Analysis
- 2. Composite Score for SDG 7 Progress
- 3. Countries That Have Made Significant Progress
- 4. Characteristics of Top Performing Countries
- 5. Time Series Analysis for Top Performing Countries
-
D.
Economic Impact Assessment
- 1. Correlation Analysis between Renewable Energy Consumption and GDP Growth Rate
- 2. Regression Analysis
- 3. Case Studies of Countries with Significant Renewable Energy Growth
-
E.
Regional Cooperation Framework
- 1. Hierarchical Clustering
- 2. Potential Region Leaders in Renewable Energy Adoption
-
IV.
Renewable Energy Adoption in Africa: Kenya's Case Study
- 1. Renewable Energy Consumption in Kenya (1990-2021)
- 2. Renewable Energy Consumption in Kenya compared with the Top Three Performing Countries in Africa 1990-2021
- 3. Renewable Energy Consumption for Kenya and the Top 20 Countries
- 4. Kenya's Comparison with Countries with the Lowest and Highest Renewable Energy Consumption Rates in 2021
Data Overview and Setup¶
A. Data Sources and Metrics¶
UN SDG Indicators Database
The UN SDG Indicators Database is a global platform managed by the United Nations Statistics Division that tracks progress toward achieving the Sustainable Development Goals (SDGs). The database contains a wide range of official indicators used to measure progress on the 17 SDGs, which cover critical areas such as poverty, hunger, health, education, gender equality, clean energy, climate action, and more.
URL: https://unstats.un.org/sdgs/dataportal/database
Access Method: API
Licence: CC-BY
Metrics:
1. Proportion of population with access to electricity (%)
2. Proportion of population with primary reliance on clean fuels and technology (%)
3. Renewable energy share in the total final energy consumption (%)
4. Energy intensity level of primary energy (megajoules per constant 2017 purchasing power parity GDP)
5. Installed renewable electricity-generating capacity (watts per capita)
6. International financial flows to developing countries in support of clean energy research and development and renewable energy production, including in hybrid systems (millions of constant 2021 United States dollars)
Gapminder Database
The Gapminder Database is a comprehensive, open-source dataset that provides global statistics on various socio-economic and environmental indicators. Gapminder's data is sourced from reliable global organizations, such as the United Nations, World Bank, and World Health Organization, and is presented in an interactive and accessible format through the Gapminder tools, enabling users to visualize trends and patterns across countries and over time.
URL: https://www.gapminder.org/data/
Access Method: CSV download
Licence: CC-BY
Metrics:
1. Foreign Investment inflows (direct, net % of GDP)
2. GDP per capita (Price and inflation adjusted in PPP$2017)
3. GDP
B. Data Processing¶
1. Data Cleaning and Transformation
i) Transposing Data:Transposed the data to switch rows and columns to get it into the required format for further analysis.
ii) Filtering for Specific Years: Filtered the dataset to include only the years 1990-2021 relevant to the analysis.
iii) Deleting Unnecessary Columns: Removed columns that weren’t useful for the analysis, streamlining the dataset.
iv) Filtering for African Countries: Selected only African countries from the global dataset to focus on the African Region.
iv) Handling Missing Data: Deleted some rows where there were missing or incomplete values.
v) Renaming Columns:Renamed columns to reduce the length and ensure clarity.
vi) Converting Figures: Converted values from shorthand formats like M (millions), B (billions), and K (thousands) into whole numbers for consistency and standardization.
2. Data Enrichment
i) Calculations:Added calculated fields such as the Compound Annual Growth Rate (CAGR) and the Growth Rate for GDP and Renewable Energy Consumption to enrich the dataset with additional insights.
ii) Merging Datasets: Combined multiple datasets to create a more comprehensive file, providing a more complete view of renewable energy trends and factors influencing them.
C. Importing Required Libraries¶
import numpy as np
import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt
import seaborn as sns
import folium
import geopandas as gpd
import plotly.express as px
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import AgglomerativeClustering
import plotly.graph_objects as go
import statsmodels.api as sm
from plotly.subplots import make_subplots
from sklearn.cluster import KMeans
from matplotlib.font_manager import FontProperties
from IPython.display import HTML as html_print
from termcolor import colored
from scipy import stats
df1= pd.read_csv("C:/Users/wambu/FaithWambui/Renewable Energy in Africa/Final Data Used/Final ISO Africa Data 1990-2021.csv")
df2= pd.read_csv("C:/Users/wambu/FaithWambui/Renewable Energy in Africa/Final Data Used/Final ISO SDG7 Indicators Data 2000-2021.csv")
df3= pd.read_csv("C:/Users/wambu/FaithWambui/Renewable Energy in Africa/Final Data Used/Final ISO CAGR and 2021 Data.csv")
Exploratory Data Analysis¶
A. Descriptive Statistics¶
def print_section_title(title):
print(colored(title, 'blue', attrs=['bold', 'underline']))
def display_head_and_tail(dataframe, head=5):
display(dataframe.head(head).style.set_caption("Head"))
display(dataframe.tail(head).style.set_caption("Tail"))
def display_na(dataframe):
na_df1 = dataframe.isnull().sum().reset_index()
na_df1.columns = ['Column', 'Number of NA']
display(na_df1.style.set_caption("Number of NA Values"))
def display_quantiles(dataframe):
quantiles_df1 = dataframe.describe([0, 0.05, 0.50, 0.95, 0.99, 1]).T
display(quantiles_df1.style.format("{:.2f}").set_caption("Quantiles"))
def check_df1(dataframe, head=5):
print_section_title('Shape')
print(dataframe.shape)
print_section_title('Types')
print(dataframe.dtypes.to_frame('Data Type').style.set_caption("Data Types"))
print_section_title('Head & Tail')
display_head_and_tail(dataframe, head)
print_section_title('NA Values')
display_na(dataframe)
print_section_title('Quantiles')
display_quantiles(dataframe)
check_df1(df1)
Shape (1728, 8) Types <pandas.io.formats.style.Styler object at 0x000001BAA6124690> Head & Tail
Year | Country Name | ISO Code | Renewable energy consumption (% of total final energy consumption) | GDP/Capita | GDP | GDP Growth Rate | FDI/GDP (%) | |
---|---|---|---|---|---|---|---|---|
0 | 1990 | Angola | AGO | 72.300000 | 4260 | nan | nan | nan |
1 | 1991 | Angola | AGO | 71.900000 | 4300 | nan | nan | nan |
2 | 1992 | Angola | AGO | 72.700000 | 4030 | nan | nan | nan |
3 | 1993 | Angola | AGO | 71.300000 | 3050 | 5880.000000 | nan | 5.140000 |
4 | 1994 | Angola | AGO | 72.200000 | 3070 | 4430.000000 | -24.659864 | 3.840000 |
Year | Country Name | ISO Code | Renewable energy consumption (% of total final energy consumption) | GDP/Capita | GDP | GDP Growth Rate | FDI/GDP (%) | |
---|---|---|---|---|---|---|---|---|
1723 | 2017 | Zimbabwe | ZWE | 82.000000 | 2330 | 17600.000000 | -14.146341 | 1.750000 |
1724 | 2018 | Zimbabwe | ZWE | 79.700000 | 2400 | 34200.000000 | 94.318182 | 2.100000 |
1725 | 2019 | Zimbabwe | ZWE | 81.000000 | 2200 | 21800.000000 | -36.257310 | 1.140000 |
1726 | 2020 | Zimbabwe | ZWE | 84.100000 | 1990 | 21500.000000 | -1.376147 | 0.699000 |
1727 | 2021 | Zimbabwe | ZWE | 82.400000 | 2120 | 28400.000000 | 32.093023 | 0.881000 |
NA Values
Column | Number of NA | |
---|---|---|
0 | Year | 0 |
1 | Country Name | 0 |
2 | ISO Code | 0 |
3 | Renewable energy consumption (% of total final energy consumption) | 25 |
4 | GDP/Capita | 0 |
5 | GDP | 42 |
6 | GDP Growth Rate | 96 |
7 | FDI/GDP (%) | 67 |
Quantiles
count | mean | std | min | 0% | 5% | 50% | 95% | 99% | 100% | max | |
---|---|---|---|---|---|---|---|---|---|---|---|
Year | 1728.00 | 2005.50 | 9.24 | 1990.00 | 1990.00 | 1991.00 | 2005.50 | 2020.00 | 2021.00 | 2021.00 | 2021.00 |
Renewable energy consumption (% of total final energy consumption) | 1703.00 | 62.04 | 29.99 | 0.10 | 0.10 | 3.00 | 74.30 | 94.50 | 96.90 | 98.30 | 98.30 |
GDP/Capita | 1728.00 | 4873.90 | 5689.83 | 387.00 | 387.00 | 849.00 | 2630.00 | 16665.00 | 28100.00 | 36300.00 | 36300.00 |
GDP | 1686.00 | 27941.43 | 66002.38 | 72.30 | 72.30 | 492.50 | 6675.00 | 129750.00 | 390800.00 | 574000.00 | 574000.00 |
GDP Growth Rate | 1632.00 | 7.09 | 18.90 | -84.10 | -84.10 | -18.09 | 6.34 | 32.59 | 71.12 | 305.52 | 305.52 |
FDI/GDP (%) | 1661.00 | 3.70 | 9.08 | -82.90 | -82.90 | -0.33 | 1.83 | 12.10 | 39.42 | 162.00 | 162.00 |
def print_section_title(title):
print(colored(title, 'blue', attrs=['bold', 'underline']))
def display_head_and_tail(dataframe, head=5):
display(dataframe.head(head).style.set_caption("Head"))
display(dataframe.tail(head).style.set_caption("Tail"))
def display_na(dataframe):
na_df2 = dataframe.isnull().sum().reset_index()
na_df2.columns = ['Column', 'Number of NA']
display(na_df2.style.set_caption("Number of NA Values"))
def display_quantiles(dataframe):
quantiles_df2 = dataframe.describe([0, 0.05, 0.50, 0.95, 0.99, 1]).T
display(quantiles_df2.style.format("{:.2f}").set_caption("Quantiles"))
def check_df2(dataframe, head=5):
print_section_title('Shape')
print(dataframe.shape)
print_section_title('Types')
print(dataframe.dtypes.to_frame('Data Type').style.set_caption("Data Types"))
print_section_title('Head & Tail')
display_head_and_tail(dataframe, head)
print_section_title('NA Values')
display_na(dataframe)
print_section_title('Quantiles')
display_quantiles(dataframe)
check_df2(df2)
Shape (1144, 9) Types <pandas.io.formats.style.Styler object at 0x000001BAA0A61990> Head & Tail
Year | Country Name | ISO Code | Renewable energy consumption (% of total final energy consumption) | Renewable Capacity(Watts/capita) | Renewable Support(USD-M) | Energy Intensity Level(MJ_PER_GDP_CON_PPP_USD) | Clean Energy (%) | Elec Access (%) | |
---|---|---|---|---|---|---|---|---|---|
0 | 2000 | Angola | AGO | 73.800000 | 14.369780 | 0.000000 | 3.770000 | 40.900000 | 24.200000 |
1 | 2001 | Angola | AGO | 72.800000 | 13.911210 | 0.000000 | 3.740000 | 41.350000 | 20.000000 |
2 | 2002 | Angola | AGO | 70.800000 | 13.454910 | 0.000000 | 3.410000 | 41.500000 | 26.300000 |
3 | 2003 | Angola | AGO | 65.600000 | 13.003400 | 0.050000 | 3.560000 | 42.100000 | 27.400000 |
4 | 2004 | Angola | AGO | 62.300000 | 26.401130 | 0.040000 | 3.230000 | 41.800000 | 28.400000 |
Year | Country Name | ISO Code | Renewable energy consumption (% of total final energy consumption) | Renewable Capacity(Watts/capita) | Renewable Support(USD-M) | Energy Intensity Level(MJ_PER_GDP_CON_PPP_USD) | Clean Energy (%) | Elec Access (%) | |
---|---|---|---|---|---|---|---|---|---|
1139 | 2017 | Zimbabwe | ZWE | 82.000000 | 60.002570 | 6.450000 | 13.620000 | 30.100000 | 44.000000 |
1140 | 2018 | Zimbabwe | ZWE | 79.700000 | 78.965220 | 0.010000 | 13.640000 | 30.300000 | 45.400000 |
1141 | 2019 | Zimbabwe | ZWE | 81.000000 | 77.621130 | 0.270000 | 14.350000 | 30.300000 | 46.700000 |
1142 | 2020 | Zimbabwe | ZWE | 84.100000 | 76.203600 | 0.060000 | 15.050000 | 30.500000 | 52.700000 |
1143 | 2021 | Zimbabwe | ZWE | 82.400000 | 75.527820 | 0.010000 | 14.770000 | 30.500000 | 49.000000 |
NA Values
Column | Number of NA | |
---|---|---|
0 | Year | 0 |
1 | Country Name | 0 |
2 | ISO Code | 0 |
3 | Renewable energy consumption (% of total final energy consumption) | 12 |
4 | Renewable Capacity(Watts/capita) | 0 |
5 | Renewable Support(USD-M) | 0 |
6 | Energy Intensity Level(MJ_PER_GDP_CON_PPP_USD) | 12 |
7 | Clean Energy (%) | 22 |
8 | Elec Access (%) | 16 |
Quantiles
count | mean | std | min | 0% | 5% | 50% | 95% | 99% | 100% | max | |
---|---|---|---|---|---|---|---|---|---|---|---|
Year | 1144.00 | 2010.50 | 6.35 | 2000.00 | 2000.00 | 2001.00 | 2010.50 | 2020.00 | 2021.00 | 2021.00 | 2021.00 |
Renewable energy consumption (% of total final energy consumption) | 1132.00 | 61.25 | 29.76 | 0.10 | 0.10 | 5.36 | 73.65 | 94.10 | 96.77 | 98.30 | 98.30 |
Renewable Capacity(Watts/capita) | 1144.00 | 31.60 | 42.66 | 0.00 | 0.00 | 0.00 | 13.56 | 135.64 | 173.78 | 209.52 | 209.52 |
Renewable Support(USD-M) | 1144.00 | 56.76 | 231.59 | 0.00 | 0.00 | 0.00 | 0.26 | 267.58 | 1052.88 | 4951.88 | 4951.88 |
Energy Intensity Level(MJ_PER_GDP_CON_PPP_USD) | 1132.00 | 6.42 | 3.85 | 0.90 | 0.90 | 2.59 | 5.26 | 14.12 | 20.21 | 26.91 | 26.91 |
Clean Energy (%) | 1122.00 | 24.66 | 31.82 | 0.00 | 0.00 | 0.30 | 7.50 | 98.10 | 99.80 | 99.90 | 99.90 |
Elec Access (%) | 1128.00 | 43.41 | 29.02 | 0.80 | 0.80 | 6.00 | 40.05 | 99.26 | 100.00 | 100.00 | 100.00 |
def print_section_title(title):
print(colored(title, 'blue', attrs=['bold', 'underline']))
def display_head_and_tail(dataframe, head=5):
display(dataframe.head(head).style.set_caption("Head"))
display(dataframe.tail(head).style.set_caption("Tail"))
def display_na(dataframe):
na_df3 = dataframe.isnull().sum().reset_index()
na_df3.columns = ['Column', 'Number of NA']
display(na_df3.style.set_caption("Number of NA Values"))
def display_quantiles(dataframe):
quantiles_df3 = dataframe.describe([0, 0.05, 0.50, 0.95, 0.99, 1]).T
display(quantiles_df3.style.format("{:.2f}").set_caption("Quantiles"))
def check_df3(dataframe, head=5):
print_section_title('Shape')
print(dataframe.shape)
print_section_title('Types')
print(dataframe.dtypes.to_frame('Data Type').style.set_caption("Data Types"))
print_section_title('Head & Tail')
display_head_and_tail(dataframe, head)
print_section_title('NA Values')
display_na(dataframe)
print_section_title('Quantiles')
display_quantiles(dataframe)
check_df3(df3)
Shape (54, 7) Types <pandas.io.formats.style.Styler object at 0x000001BAA6A98E50> Head & Tail
Country Name | Renewable energy consumption (% of total final energy consumption) | ISO Code | CAGR (1990-2021) | CAGR (2016-2021) | FDI/GDP (%) | GDP/Capita | |
---|---|---|---|---|---|---|---|
0 | Algeria | 0.100000 | DZA | -0.022111 | 0.000000 | 0.467000 | 11000 |
1 | Angola | 52.900000 | AGO | -0.010027 | 0.019206 | -6.550000 | 5910 |
2 | Benin | 54.500000 | BEN | -0.017329 | 0.037213 | 1.960000 | 3320 |
3 | Botswana | 27.400000 | BWA | -0.018576 | 0.005189 | -1.700000 | 14900 |
4 | Burkina Faso | 71.200000 | BFA | -0.006185 | -0.015796 | -0.407000 | 2180 |
Country Name | Renewable energy consumption (% of total final energy consumption) | ISO Code | CAGR (1990-2021) | CAGR (2016-2021) | FDI/GDP (%) | GDP/Capita | |
---|---|---|---|---|---|---|---|
49 | Togo | 75.100000 | TGO | -0.001509 | -0.014281 | -1.630000 | 2140 |
50 | Tunisia | 11.600000 | TUN | -0.007172 | -0.013250 | 1.170000 | 10400 |
51 | Uganda | 91.000000 | UGA | -0.001925 | -0.000877 | 4.070000 | 2250 |
52 | Zambia | 83.000000 | ZMB | 0.000000 | -0.002392 | 1.780000 | 3240 |
53 | Zimbabwe | 82.400000 | ZWE | 0.008185 | 0.001708 | 0.881000 | 2120 |
NA Values
Column | Number of NA | |
---|---|---|
0 | Country Name | 0 |
1 | Renewable energy consumption (% of total final energy consumption) | 0 |
2 | ISO Code | 0 |
3 | CAGR (1990-2021) | 0 |
4 | CAGR (2016-2021) | 0 |
5 | FDI/GDP (%) | 2 |
6 | GDP/Capita | 0 |
Quantiles
count | mean | std | min | 0% | 5% | 50% | 95% | 99% | 100% | max | |
---|---|---|---|---|---|---|---|---|---|---|---|
Renewable energy consumption (% of total final energy consumption) | 54.00 | 55.68 | 30.24 | 0.10 | 0.10 | 4.47 | 67.25 | 91.96 | 95.82 | 96.30 | 96.30 |
CAGR (1990-2021) | 54.00 | -0.01 | 0.01 | -0.09 | -0.09 | -0.03 | -0.01 | 0.00 | 0.01 | 0.01 | 0.01 |
CAGR (2016-2021) | 54.00 | -0.00 | 0.03 | -0.08 | -0.08 | -0.04 | -0.00 | 0.04 | 0.06 | 0.07 | 0.07 |
FDI/GDP (%) | 52.00 | 3.75 | 5.73 | -6.55 | -6.55 | -1.66 | 2.05 | 12.00 | 23.82 | 32.80 | 32.80 |
GDP/Capita | 54.00 | 5536.07 | 5795.20 | 396.00 | 396.00 | 988.80 | 3235.00 | 16790.00 | 24049.00 | 27600.00 | 27600.00 |
B. Renewable Energy Consumption in African Countries 1990-2021¶
1. Progression of Renewable Energy Adoption¶
# Animated choropleth map
fig = px.choropleth(df1,
locations="ISO Code",
locationmode="ISO-3",
color="Renewable energy consumption (% of total final energy consumption)",
hover_name="Country Name",
animation_frame="Year", # To create the animation over years
color_continuous_scale=px.colors.sequential.Viridis,
projection="natural earth",
title="Progression of Renewable Energy Adoption in Africa",
labels={'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy Consumption (%)'}) # Custom color scale name)
# Updating layout to focus on Africa and enlarge the map
fig.update_geos(
showcoastlines=True, coastlinecolor="Black",
showland=True, landcolor="white",
showocean=True, oceancolor="white",
showlakes=True, lakecolor="LightBlue",
scope="africa"
)
# Enlarge the figure size
fig.update_layout(
width=1000, # Set the width of the figure
height=800, # Set the height of the figure
margin={"r":0,"t":50,"l":0,"b":0} # Adjust margins to make the map bigger
)
fig.write_html('animated_map.html')
# Show the map
fig.show()
Overall Observation: The map provides a visual representation of the varying levels of renewable energy consumption across the African continent from 1990 to 2021. The colour-coded scale indicates the percentage of renewable energy in each country's energy mix.
Key Findings: Regional Variations: There are significant regional disparities in renewable energy adoption. Countries in North Africa and Southern Africa generally have higher levels of renewable energy consumption, while Central and West African countries tend to have lower levels.Clustering: Certain regions, such as the Horn of Africa and parts of Southern Africa, exhibit clustering of countries with similar levels of renewable energy adoption.
Outliers: A few countries stand out with exceptionally high or low levels of renewable energy consumption, suggesting unique factors influencing their energy mix.
2. Trends in Renewable Energy Consumption¶
african_countries = sorted(df1['Country Name'].unique().tolist())
fig = go.Figure()
for country in african_countries:
country_data = df1[df1['Country Name'] == country]
fig.add_trace(
go.Scatter(
x=country_data['Year'],
y=country_data['Renewable energy consumption (% of total final energy consumption)'],
mode='lines+markers',
name=country,
visible=True
)
)
# Create and add dropdown menu for multi-select
updatemenus = list([
dict(
buttons=[
dict(
args=[{'visible': [True for _ in african_countries]},
{'title': 'Renewable Energy Consumption in All African Countries'}],
label="Select All",
method='update'
),
dict(
args=[{'visible': [False for _ in african_countries]},
{'title': 'Renewable Energy Consumption in Selected African Countries'}],
label="Deselect All",
method='update'
)
] + [
dict(
args=[{'visible': [country == c for c in african_countries]},
{'title': f'Renewable Energy Consumption in {country}'}],
label=country,
method='update'
) for country in african_countries
],
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.1,
xanchor="left",
y=1.1,
yanchor="top"
),
])
# Update layout
fig.update_layout(
updatemenus=updatemenus,
xaxis_title='Year',
yaxis_title='Renewable Energy Consumption (%)',
hovermode='x'
)
# Add range slider and selector
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=5, label="Last 5 years", step="year", stepmode="backward"),
dict(count=10, label="Last 10 years", step="year", stepmode="backward"),
dict(count=20, label="Last 20 years", step="year", stepmode="backward"),
dict(step="all")
])
),
rangeslider=dict(
visible=True
),
type="date"
)
)
# Show the figure
fig.show()
Graph Description: This multi-line graph presents the renewable energy consumption percentage (%) of the different African countries from 1990 to 2021. The x-axis represents the years, and the y-axis represents the percentage of total energy consumption that comes from renewable sources. The trend line shows how the selected countrys' renewable energy consumption has evolved over the decades.
3. Top and Bottom Performers in Renewable Energy Consumption¶
# Grouping by 'Country' and calculating the mean of 'Renewable Energy Consumption'
averaged_df1 = df1.groupby('Country Name')['Renewable energy consumption (% of total final energy consumption)'].mean().reset_index()
# Sorting by the averaged 'Renewable Energy Consumption'
sorted_averaged_df1 = averaged_df1.sort_values(by='Renewable energy consumption (% of total final energy consumption)', ascending=False)
# Displaying top 10 performers
top_performers = sorted_averaged_df1.head(10)
print("Top 10 Performers (Averaged):")
print(top_performers)
# Displaying bottom 10 performers
bottom_performers = sorted_averaged_df1.tail(10)
print("\nBottom 10 Performers (Averaged):")
print(bottom_performers)
Top 10 Performers (Averaged): Country Name \ 11 Congo, Dem. Rep. 51 Uganda 19 Ethiopia 44 Somalia 5 Burundi 8 Central African Republic 27 Liberia 48 Tanzania 24 Guinea-Bissau 35 Mozambique Renewable energy consumption (% of total final energy consumption) 11 96.462500 51 94.246875 19 93.918750 44 92.740625 5 92.296875 8 91.965625 27 89.890625 48 89.028125 24 88.262500 35 87.940625 Bottom 10 Performers (Averaged): Country Name \ 14 Djibouti 7 Cape Verde 33 Mauritius 34 Morocco 50 Tunisia 45 South Africa 15 Egypt 28 Libya 42 Seychelles 0 Algeria Renewable energy consumption (% of total final energy consumption) 14 30.284375 7 25.125000 33 20.950000 34 15.546875 50 13.703125 45 12.275000 15 7.053125 28 2.690625 42 1.653125 0 0.312500
# Creating subplots for better comparison
fig, axes = plt.subplots(2, 1, figsize=(12, 6), sharex=True)
# Top Performers Plot
sns.barplot(x='Renewable energy consumption (% of total final energy consumption)', y='Country Name',
data=top_performers, palette='Greens_d', ax=axes[0])
axes[0].set_title('Top 10 Performers in Renewable Energy Consumption', fontsize=12)
axes[0].set_xlabel('') # Remove x-axis label for the top plot to avoid redundancy
axes[0].set_ylabel('Country', fontsize=10)
axes[0].bar_label(axes[0].containers[0], fmt='%.2f', label_type='edge') # Add data labels
# Bottom Performers Plot
sns.barplot(x='Renewable energy consumption (% of total final energy consumption)', y='Country Name',
data=bottom_performers, palette='Reds_d', ax=axes[1])
axes[1].set_title('Bottom 10 Performers in Renewable Energy Consumption', fontsize=12)
axes[1].set_xlabel('Renewable Energy Consumption (%Total Final)', fontsize=10)
axes[1].set_ylabel('Country', fontsize=12)
axes[1].bar_label(axes[1].containers[0], fmt='%.2f', label_type='edge') # Add data labels
# Adjust layout and show the plot
plt.show()
Overall Observation:The chart presents a horizontal bar chart comparing the top 10 and bottom 10 performers in renewable energy consumption among African countries. The length of each bar represents the percentage of renewable energy in the country's total final energy consumption.
Key Findings: Top Performers: The top 10 performers exhibit a wide range of renewable energy consumption, with Congo, Democratic Republic leading the pack. Countries like Ethiopia, Uganda, and Somalia also demonstrate significant adoption of renewable energy.Bottom Performers: The bottom 10 performers generally have lower levels of renewable energy consumption. Countries like Algeria, Seychelles, and Libya have particularly low percentages.
Regional Trends: The chart reveals that countries in Central and East Africa tend to perform better in terms of renewable energy adoption compared to those in North and West Africa.
4. Most Improved Countries¶
# Calculate the annual change
df1['Annual Change'] = df1.groupby('Country Name')['Renewable energy consumption (% of total final energy consumption)'].diff()
# Group by Country and periods of 10 years to get the periodic changes
period_years = 10
periodic_changes = df1.groupby(['Country Name', (df1['Year'] // period_years) * period_years])['Annual Change'].sum().reset_index()
# Get the top 10 countries based on the total change rate
top_countries = periodic_changes.groupby('Country Name')['Annual Change'].sum().sort_values(ascending=False).head(10)
# Plot the bar chart and capture the Axes object
ax = top_countries.plot(kind='bar', figsize=(10, 5), title='Most Improved Countries', xlabel='Country', ylabel='Total Change Rate')
plt.xticks(rotation=45)
# Add labels on top of the bars
for i, v in enumerate(top_countries):
ax.text(i, v + 0.01, f"{v:.2f}", ha='center', va='bottom', fontsize=12, color='black')
# Show the plot
plt.show()
Overall Observation:The chart displays a vertical bar chart ranking the most improved 10 countries based on their "Total Change Rate" in renewable energy consumption. The height of each bar represents the percentage change in renewable energy consumption.
Key Findings: Dominance of Zimbabwe:Zimbabwe stands out as the top performer with a significantly higher Total Change Rate compared to other countries.Clustering: There is a clustering of countries with Total Change Rates between 5% and 10%, indicating a group of countries with moderate improvement.
Diverse Group: The top 10 includes countries from various regions of Africa, indicating that progress in renewable energy adoption is not limited to specific geographic areas.
Outliers: A few countries, such as Zambia and Cape Verde, have very low Total Change Rates.
5. Least Improved Countries¶
df1['Annual Change'] = df1.groupby('Country Name')['Renewable energy consumption (% of total final energy consumption)'].diff()
period_years = 10
periodic_changes = df1.groupby(['Country Name', (df1['Year'] // period_years) * period_years])['Annual Change'].sum().reset_index()
bottom_countries = periodic_changes.groupby('Country Name')['Annual Change'].sum().sort_values().head(10)
ax=bottom_countries.plot(kind='bar', figsize=(12, 6), title='Least Improving Countries', xlabel='Country', ylabel='Total Change Rate')
# Add labels on top of the bars
for i, v in enumerate(bottom_countries):
ax.text(i, v + 0.01, f"{v:.2f}", ha='center', va='top', fontsize=12, color='black')
plt.xticks(rotation=45)
plt.show()
Overall Observation:The chart displays a vertical bar chart ranking the lowest 10 performers in terms of "Total Change Rate" in renewable energy consumption. The height of each bar represents the percentage change in renewable energy consumption for that country.
Key Findings: Negative Changes: All of the countries listed have experienced negative changes in their renewable energy consumption, indicating a decline in their adoption rates.Significant Decline: Equatorial Guinea stands out with the most significant decline in renewable energy consumption.
6. Average Renewable Energy Growth Rate¶
# Sorting the dataframe
df1 = df1.sort_values(['Country Name', 'Year'])
# Calculating the year-over-year change
df1['YoY_Change'] = df1.groupby('Country Name')['Renewable energy consumption (% of total final energy consumption)'].pct_change() * 100
df1['YoY_Change'] = df1['YoY_Change'].fillna(0)
# Calculating the simple average growth rate
average_growth_rate = df1['YoY_Change'].mean()
print(f"Simple Average Growth Rate: {average_growth_rate:.2f}%")
# Plotting the average renewable energy percentage over time
yearly_average = df1.groupby('Year')['Renewable energy consumption (% of total final energy consumption)'].mean()
plt.figure(figsize=(12, 6))
plt.plot(yearly_average.index, yearly_average.values)
plt.title('Average Renewable Energy Consumption Across African Countries')
plt.xlabel('Year')
plt.ylabel('Average Renewable Energy Consumption (%Total Final)')
plt.show()
C:\Users\wambu\AppData\Local\Temp\ipykernel_11112\3870675418.py:5: FutureWarning: The default fill_method='ffill' in SeriesGroupBy.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.
Simple Average Growth Rate: -0.62%
Overall Observation:The chart displays a line graph representing the average renewable energy consumption (%Total Final) across African countries from 1990 to 2020. The graph also includes a simple average growth rate of -0.62%.
Key Findings: Declining Trend:The overall trend is downward, indicating a decline in average renewable energy consumption across African countries over the period.Fluctuations: While the general trend is downward, there are some fluctuations in the data, suggesting periods of slight increases or decreases.
Simple Average Growth Rate: The calculated simple average growth rate of -0.62% confirms the overall downward trend.
# Plotting the distribution of growth rates
plt.figure(figsize=(12, 6))
plt.hist(df1['YoY_Change'], bins=50)
plt.title('Distribution of Year-over-Year Changes in Renewable Energy Consumption')
plt.xlabel('Year-over-Year Change (%)')
plt.ylabel('Frequency')
plt.show()
Overall Observation: The chart displays a right-skewed distribution of year-over-year changes in renewable energy consumption. This means that there is a greater frequency of smaller percentage increases, with fewer, but larger, increases occurring.
Key Findings: Positive Bias: The majority of changes are positive, indicating that renewable energy consumption is generally increasing year over year.Clustering: There is a clear clustering of data around the 0% mark, suggesting that many years experience relatively small changes in renewable energy consumption.
Outliers: A few outliers exist on the right side of the distribution, representing years with exceptionally high growth rates in renewable energy consumption.
Skewness: The right-skewness suggests that the distribution is influenced by a few large increases, which can skew the mean towards the right.
C. Comparative Analysis of Renewable Energy and Socio-Economic Indicators¶
1. GDP per Capita vs. Renewable Energy Percentage¶
# List of African countries
african_countries = sorted(df1['Country Name'].unique().tolist())
# Create figure
fig = go.Figure()
# Loop through each African country and add a trace
for country in african_countries:
country_data = df1[df1['Country Name'] == country]
fig.add_trace(
go.Scatter(
x=country_data['GDP/Capita'],
y=country_data['Renewable energy consumption (% of total final energy consumption)'],
mode='markers',
name=country,
text=country_data['Year'], # Display the year on hover
visible=True
)
)
# Create and add dropdown menu for multi-select
updatemenus = list([
dict(
buttons=[
dict(
args=[{'visible': [True for _ in african_countries]},
{'title': 'GDP per Capita vs Renewable Energy Consumption in All African Countries'}],
label="Select All",
method='update'
),
dict(
args=[{'visible': [False for _ in african_countries]},
{'title': 'GDP per Capita vs Renewable Energy Consumption in Selected African Countries'}],
label="Deselect All",
method='update'
)
] + [
dict(
args=[{'visible': [country == c for c in african_countries]},
{'title': f'GDP per Capita vs Renewable Energy Consumption in {country}'}],
label=country,
method='update'
) for country in african_countries
],
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.1,
xanchor="left",
y=1.1,
yanchor="top"
),
])
# Update layout
fig.update_layout(
updatemenus=updatemenus,
xaxis_title='GDP per Capita (USD)',
yaxis_title='Renewable Energy Consumption (%Total Final)',
title='GDP per Capita vs Renewable Energy Consumption in African Countries',
hovermode='closest',
xaxis=dict(type='log') # Optional: Use logarithmic scale for GDP per Capita
)
# Add range slider and selector for year (optional)
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=5, label="Last 5 years", step="year", stepmode="backward"),
dict(count=10, label="Last 10 years", step="year", stepmode="backward"),
dict(count=20, label="Last 20 years", step="year", stepmode="backward"),
dict(step="all")
])
),
rangeslider=dict(
visible=True
),
type="linear" # Keep it linear for GDP per Capita
)
)
# Show the figure
fig.show()
Overall Observation:The chart displays a scatter plot comparing GDP per capita to renewable energy consumption (%Total Final) for all African countries. Each dot represents a year, and the different colors represent different countries.
Key Findings: Inverse Relationship: There is a noticeable trend of decreasing renewable energy consumption as GDP per capita increases.Clustering: Some clustering of data points can be observed, suggesting that certain groups of countries may share similar characteristics in terms of GDP per capita and renewable energy consumption.
High-Income, Low Renewable Energy Use:Countries with higher GDP per capita (above 10k USD) have lower renewable energy consumption.
2. FDI/GDP % vs. Renewable Energy Percentage for African Countries 1990-2021¶
african_countries = sorted(df1['Country Name'].unique().tolist())
fig = go.Figure()
# Loop through each country to create traces for both FDI/GDP and Renewable Energy
for country in african_countries:
country_data = df1[df1['Country Name'] == country]
# FDI/GDP Ratio trace
fig.add_trace(
go.Bar(
x=country_data['Year'],
y=country_data['FDI/GDP (%)'],
name=f'{country} FDI/GDP%',
visible=True
)
)
# Renewable Energy Consumption trace
fig.add_trace(
go.Bar(
x=country_data['Year'],
y=country_data['Renewable energy consumption (% of total final energy consumption)'],
name=f'{country} Renewable Energy %',
visible=True
)
)
# Create dropdown menu for multi-select
updatemenus = list([
dict(
buttons=[
dict(
args=[{'visible': [True for _ in range(2 * len(african_countries))]},
{'title': 'FDI/GDP% vs Renewable Energy in All African Countries'}],
label="Select All",
method='update'
),
dict(
args=[{'visible': [False for _ in range(2 * len(african_countries))]},
{'title': 'FDI/GDP% vs Renewable Energy in Selected African Countries'}],
label="Deselect All",
method='update'
)
] + [
dict(
args=[{'visible': [(country == c or country == c) for c in african_countries for _ in range(2)]},
{'title': f'FDI/GDP% vs Renewable Energy in {country}'}],
label=country,
method='update'
) for country in african_countries
],
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.1,
xanchor="left",
y=1.1,
yanchor="top"
),
])
# Update layout
fig.update_layout(
updatemenus=updatemenus,
barmode='group', # Group bars together for comparison
xaxis_title='Year',
yaxis_title='Values',
hovermode='x'
)
# Add range slider and selector
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=5, label="Last 5 years", step="year", stepmode="backward"),
dict(count=10, label="Last 10 years", step="year", stepmode="backward"),
dict(count=20, label="Last 20 years", step="year", stepmode="backward"),
dict(step="all")
])
),
rangeslider=dict(
visible=True
),
type="date"
)
)
# Show the figure
fig.show()
Graph Description: This bar graph presents the relationship between the renewable energy consumption percentage (%) and the FDI/GDP % of the different African countries from 1990 to 2021. The x-axis represents the years, and the y-axis represents the percentage of total energy consumption that comes from renewable sources and the FDI/GDP ratio.
D. SDG 7 Indicators of Renewable Energy Adoption¶
1. Renewable Energy Consumption(% of total final energy consumption)¶
heatmap_data = df2.pivot(index='Country Name', columns='Year', values='Renewable energy consumption (% of total final energy consumption)')
# Create the heatmap
plt.figure(figsize=(10, 10))
sns.heatmap(heatmap_data, annot=False, cmap="viridis")
plt.title('Renewable Energy Consumption (% of total final energy consumption)')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation:The chart displays a heatmap visualizing the trends in renewable energy consumption (% of total final energy consumption) for various African countries over the years 2000 to 2021. The color scale indicates the level of renewable energy consumption, with lighter shades representing higher levels.
Key Findings: Variation across countries: There's significant variation in renewable energy use among the countries shown. Some countries consistently use a high percentage of renewables (shown in yellow/light green), while others use much less (shown in purple/dark blue).Temporal trends:For most countries, the percentage of renewable energy consumption remains relatively stable over the 21-year period. However, there are some noticeable changes in certain countries.
High renewable users: Countries like Congo Dem. Rep., Ethiopia, and Guinea consistently show high percentages of renewable energy use (yellow/light green colors).
Low renewable users: Countries such as Algeria, Egypt, and Tunisia show consistently low percentages of renewable energy use (purple/dark blue colors).
Changing patterns: Some countries show significant changes over time. For example, South Sudan has data only from around 2011 onwards, likely due to its independence in that year.
Data gaps:There are some white spaces in the chart, particularly for South Sudan, which might indicate missing data or the country not existing as an independent nation for part of the time period.
Recent trends:For many countries, there seems to be little change in the most recent years (2018-2021), suggesting relatively stable renewable energy consumption patterns.
Diverse energy landscapes: The chart highlights the diverse energy landscapes across African nations, likely influenced by factors such as natural resources, economic development, and energy policies.
2. Renewable Energy Capacity¶
heatmap_data = df2.pivot(index='Country Name', columns='Year', values='Renewable Capacity(Watts/capita)')
# Create the heatmap
plt.figure(figsize=(10, 10))
sns.heatmap(heatmap_data, annot=False, cmap="Blues")
plt.title('Distribution of Renewable Capacity (Watts/Capita)')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation:This heatmap displays the renewable energy capacity per capita in watts for various African countries from 2000 to 2021. The color scale ranges from light blue (low capacity) to dark blue (high capacity).
Key Findings i) Most countries exhibit very low renewable energy capacity throughout the period.ii) Mauritius and Namibia stand out with higher capacities.
iii) There's a general trend of increasing capacity over time, especially in the last decade.
iv) Significant disparity exists between countries in renewable energy development.
v) Some countries show rapid growth in capacity, while others remain stagnant.
3. Renewable Energy Investments¶
heatmap_data = df2.pivot(index='Country Name', columns='Year', values='Renewable Support(USD-M)')
# Create the heatmap
plt.figure(figsize=(10, 10))
sns.heatmap(heatmap_data, annot=False, cmap="Greens")
plt.title('Renewable Investment Support (USD-M)')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation:This heatmap shows the investment support for renewable energy in millions of USD for African countries from 2000 to 2021. The color scale goes from light green (low investment) to dark green (high investment).
Key Findings: i) Investment patterns are sporadic and vary greatly between countries and years.ii) Most countries experience occasional spikes in investment rather than consistent support.
iii) Algeria receives a significant investment in 2021, indicated by the dark green color.
iv) Investments become more frequent from 2010 onwards.
v) Some countries show little to no investment throughout the entire period.
4. Energy Intensity Level¶
heatmap_data = df2.pivot(index='Country Name', columns='Year', values='Energy Intensity Level(MJ_PER_GDP_CON_PPP_USD)')
# Create the heatmap
plt.figure(figsize=(10, 10))
sns.heatmap(heatmap_data, annot=False, cmap="Reds")
plt.title('Energy Intensity Level')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation:This heatmap illustrates the energy intensity levels for African countries from 2000 to 2021. The color scale ranges from light pink (low intensity) to dark red (high intensity).
Key Findings: i) Energy intensity varies significantly between countries.ii) Countries like Mozambique, Zimbabwe and Congo Dem. Rep. consistently show high energy intensity.
iii) Many countries demonstrate a gradual decrease in energy intensity over time.
iv) Some countries, such as Libya and Niger, show fluctuations in energy intensity.
v) Data for South Sudan starts around 2011, likely due to its recent independence.
5. Access to Modern Energy Services¶
heatmap_data = df2.pivot(index='Country Name', columns='Year', values='Elec Access (%)')
# Create the heatmap
plt.figure(figsize=(10, 10))
sns.heatmap(heatmap_data, annot=False, cmap="RdYlGn")
plt.title('Elec Access (%)')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation:This heatmap shows the percentage of population with access to electricity in African countries from 2000 to 2021. The color scale goes from red (low access) to green (high access).
Key Findings: i) There's a clear divide between countries with high access and those with low access.ii) Many countries show steady improvement in electricity access over time.
iii) Algeria, Egypt,Tunisia, and Mauritius maintain near 100% access throughout the period.
iv) Countries like Burundi, Chad, and Niger consistently have very low access rates.
v) Most countries demonstrate at least some improvement from 2000 to 2021.
6. Access to Clean Energy¶
heatmap_data = df2.pivot(index='Country Name', columns='Year', values=' Clean Energy (%)')
# Create the heatmap
plt.figure(figsize=(10, 10))
sns.heatmap(heatmap_data, annot=False, cmap="YlGnBu")
plt.title('Clean Energy Access (%)')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation:This heatmap displays the percentage of population with access to clean energy sources in African countries from 2000 to 2021. The color scale ranges from light yellow (low access) to dark blue (high access).
Key Findings: i) There's high variability in clean energy access between countries.ii) Algeria, Egypt,Tunisia, and Mauritius maintain high clean energy access throughout the period.
iii) Many countries show gradual improvement over time, particularly in the last decade.
iv) Some countries, such as Chad and Somalia, consistently have very low clean energy access.
v) The overall trend suggests increasing clean energy access across most countries, but at varying rates.
Detailed Analysis¶
A. Strategic Energy Transition Planning¶
1. Compound Annual Growth Rate (CAGR) for Renewable Energy Consumption (1990-2021)¶
# Function to calculate CAGR
def calculate_cagr(start_value, end_value, num_years):
return (end_value / start_value) ** (1 / num_years) - 1
# Filter the DataFrame for the years 1990 to 2021
df1_filtered = df1[(df1['Year'] >= 1990) & (df1['Year'] <= 2021)]
# Get first and last year for each country within the filtered range
first_last = df1_filtered.groupby('Country Name').agg({
'Year': ['first', 'last'],
'Renewable energy consumption (% of total final energy consumption)': ['first', 'last']
})
# Calculate CAGR for each country
first_last['CAGR'] = calculate_cagr(
first_last[('Renewable energy consumption (% of total final energy consumption)', 'first')],
first_last[('Renewable energy consumption (% of total final energy consumption)', 'last')],
first_last[('Year', 'last')] - first_last[('Year', 'first')]
)
# Calculate average CAGR across all countries
average_cagr = first_last['CAGR'].mean() * 100
print(f"Average CAGR across countries (1990-2021): {average_cagr:.2f}%")
# Sort countries by CAGR
cagr_sorted = first_last.sort_values('CAGR', ascending=False)
# Print sorted CAGR values for each country
print(cagr_sorted[['CAGR']])
Average CAGR across countries (1990-2021): -0.91% CAGR Country Name Zimbabwe 0.008185 Gabon 0.004967 Somalia 0.003239 Congo, Rep. 0.002835 Cape Verde 0.002218 South Sudan 0.001846 Eswatini 0.001620 Congo, Dem. Rep. 0.001475 Liberia 0.001452 Libya 0.000000 Zambia 0.000000 Rwanda -0.000283 Guinea-Bissau -0.000440 Cameroon -0.000963 Central African Republic -0.001047 Madagascar -0.001359 Togo -0.001509 Uganda -0.001925 Ethiopia -0.001933 Nigeria -0.002876 Djibouti -0.003441 Eritrea -0.003477 Kenya -0.003934 Burundi -0.004172 Niger -0.004449 Malawi -0.005364 Tanzania -0.005638 Sudan -0.005908 Mozambique -0.006113 Burkina Faso -0.006185 Mali -0.006518 Sao Tome and Principe -0.007109 Tunisia -0.007172 Cote d'Ivoire -0.007544 Gambia -0.007824 Chad -0.007942 Sierra Leone -0.008383 Guinea -0.009392 Angola -0.010027 Namibia -0.011173 Egypt -0.012468 Lesotho -0.013989 Senegal -0.014401 South Africa -0.017182 Benin -0.017329 Botswana -0.018576 Comoros -0.018714 Algeria -0.022111 Morocco -0.022968 Ghana -0.023145 Mauritania -0.024047 Seychelles -0.028754 Mauritius -0.053378 Equatorial Guinea -0.086082
# Sort countries by CAGR for plotting
cagr_sorted = first_last.sort_values('CAGR', ascending=False)
# Reset index for easier plotting
cagr_sorted = cagr_sorted.reset_index()
# Plotting the CAGR values using a bar chart
plt.figure(figsize=(12, 8))
sns.barplot(x='CAGR', y='Country Name', data=cagr_sorted, palette='viridis')
# Adding labels and title
plt.xlabel('CAGR (1990-2021)')
plt.ylabel('Country Name')
plt.title('CAGR of Renewable Energy Consumption by Country (1990-2021)')
# Show the plot
plt.show()
Overall Observation:This bar chart displays the Compound Annual Growth Rate (CAGR) of renewable energy consumption for various countries in Africa from 1990 to 2021. The x-axis represents the CAGR values, ranging from approximately -0.08 (negative growth) to 0.06 (positive growth). A positive value indicates an increase in renewable energy consumption over the period, while a negative value indicates a decline. The y-axis lists the names of the countries in Africa, with each bar corresponding to a specific country.
Key Findings: Top Performers: At the top right of the chart, we see countries like Zimbabwe, Gabon, Zambia, and Malawi with positive CAGRs, indicating that these nations have significantly increased their renewable energy consumption between 1990 and 2021.Countries with Declines: On the far left of the chart, Equatorial Guinea stands out with the steepest decline, followed by South Sudan, Chad, and Botswana, all showing significant negative CAGRs.
Moderate Changes: A large number of countries are near the zero CAGR mark (center of the chart), indicating that their renewable energy consumption rates have remained relatively stable over the 30-year period. Countries like South Africa, Mozambique, and Kenya fall in this category, with slight positive or negative changes.
Trends in the Data: The chart reveals an overall diverse range of growth across African countries. While some nations have made great strides in increasing renewable energy, others have fallen behind, showing significant declines.
2. 5-Year Staggered Compound Annual Growth Rate (CAGR) for Renewable Energy Consumption (1990-2021)¶
# Define the function to calculate CAGR
def calculate_cagr(start_value, end_value, num_years):
return (end_value / start_value) ** (1 / num_years) - 1
# Define the rolling window size (e.g., 5-year CAGR)
rolling_window = 5
# Create an empty list to store results
cagr_results = []
# Loop through each country to calculate staggered CAGRs
for country in df1['Country Name'].unique():
country_data = df1[df1['Country Name'] == country].sort_values('Year')
# Calculate CAGR for each rolling window
for i in range(len(country_data) - rolling_window):
start_year = country_data.iloc[i]['Year']
end_year = country_data.iloc[i + rolling_window]['Year']
start_value = country_data.iloc[i]['Renewable energy consumption (% of total final energy consumption)']
end_value = country_data.iloc[i + rolling_window]['Renewable energy consumption (% of total final energy consumption)']
cagr_value = calculate_cagr(start_value, end_value, end_year - start_year)
# Store the results in the list
cagr_results.append({
'Country Name': country,
'Start Year': start_year,
'End Year': end_year,
'CAGR': cagr_value
})
# Convert the list of results to a DataFrame
cagr_staggered = pd.DataFrame(cagr_results)
# Display the staggered CAGR results
print(cagr_staggered)
Country Name Start Year End Year CAGR 0 Algeria 1990 1995 0.148698 1 Algeria 1991 1996 0.059224 2 Algeria 1992 1997 0.107566 3 Algeria 1993 1998 0.000000 4 Algeria 1994 1999 0.045640 ... ... ... ... ... 1453 Zimbabwe 2012 2017 0.012662 1454 Zimbabwe 2013 2018 0.001007 1455 Zimbabwe 2014 2019 0.000495 1456 Zimbabwe 2015 2020 0.008038 1457 Zimbabwe 2016 2021 0.001708 [1458 rows x 4 columns]
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Add traces for each country
for country in cagr_staggered['Country Name'].unique():
country_data = cagr_staggered[cagr_staggered['Country Name'] == country]
fig.add_trace(
go.Scatter(x=country_data['End Year'], y=country_data['CAGR'], name=country, mode='lines'),
secondary_y=False,
)
# Add range slider
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(count=5, label="5y", step="year", stepmode="backward"),
dict(count=10, label="10y", step="year", stepmode="backward"),
dict(step="all")
])
),
rangeslider=dict(visible=True),
type="date"
)
)
# Update layout
fig.update_layout(
title='Staggered CAGR of Renewable Energy Consumption (%Total Final) for Multiple Countries',
xaxis_title='End Year',
yaxis_title='CAGR',
legend_title='Country Name',
hovermode="x unified"
)
# Add dropdown menu for country selection
updatemenus = [
dict(
buttons=list([
dict(label='All Countries',
method='update',
args=[{'visible': [True] * len(fig.data)},
{'title': 'All Countries'}]),
] + [
dict(label=country,
method='update',
args=[{'visible': [country == trace.name for trace in fig.data]},
{'title': f'Staggered CAGR of Renewable Energy Consumption for {country}'}])
for country in cagr_staggered['Country Name'].unique()
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.1,
xanchor="left",
y=1.1,
yanchor="top"
),
]
fig.update_layout(updatemenus=updatemenus)
# Show the plot
fig.show()
Graph Description: This chart shows the 5 year staggered CAGR for the renewable energy consumption percentage (%) of the different African countries from 1990 to 2021. The x-axis represents the years, and the y-axis represents the staggered CAGR.
3. Cluster Analysis Based on Average Renewable Energy Consumption¶
df1_cluster = df1.groupby('Country Name')['Renewable energy consumption (% of total final energy consumption)'].mean().reset_index()
kmeans = KMeans(n_clusters=4, n_init=7, random_state=1)
df1_cluster['Cluster'] = kmeans.fit_predict(df1_cluster[['Renewable energy consumption (% of total final energy consumption)']])
fig = px.scatter(df1_cluster, x='Country Name', y='Renewable energy consumption (% of total final energy consumption)', color='Cluster',
title='Cluster Analysis of Countries Based on Renewable Energy Consumption (1990-2021)',
labels={'Renewable energy consumption (% of total final energy consumption)': 'Average Renewable Energy Consumption (%)'},
hover_data=['Country Name'])
fig.update_layout(xaxis={'categoryorder':'total ascending'})
fig.show()
# Group the countries by their assigned cluster and print the countries in each cluster
for cluster in range(kmeans.n_clusters):
countries_in_cluster = df1_cluster[df1_cluster['Cluster'] == cluster]['Country Name'].tolist()
print(f"Cluster {cluster + 0}: {', '.join(countries_in_cluster)}")
Cluster 0: Burkina Faso, Burundi, Cameroon, Central African Republic, Chad, Congo, Dem. Rep., Eritrea, Ethiopia, Gabon, Guinea, Guinea-Bissau, Liberia, Madagascar, Malawi, Mali, Mozambique, Niger, Nigeria, Rwanda, Sierra Leone, Somalia, Tanzania, Togo, Uganda, Zambia Cluster 1: Botswana, Cape Verde, Djibouti, Equatorial Guinea, Lesotho, Mauritania, Namibia, Sao Tome and Principe, Senegal, South Sudan Cluster 2: Angola, Benin, Comoros, Congo, Rep., Cote d'Ivoire, Eswatini, Gambia, Ghana, Kenya, Sudan, Zimbabwe Cluster 3: Algeria, Egypt, Libya, Mauritius, Morocco, Seychelles, South Africa, Tunisia
Overall Observation:This visualization represents a cluster analysis of African countries based on their renewable energy consumption as a percentage of total final energy use. The x-axis lists the countries, arranged by their renewable energy consumption levels. Each country is assigned to a cluster, and the labels are clearly presented in a horizontal format. The y-axis represents renewable energy consumption as a percentage of total final energy, ranging from 0% to 100%. Countries with higher percentages consume more renewable energy. Each country is color-coded based on its cluster assignment. The color gradient, from yellow to purple, distinguishes between different clusters of countries with similar renewable energy consumption patterns.
Key Findings
Main Observations
Countries like Congo, Dem. Rep., Uganda, Burundi, Somalia, Ethiopia are the highest performers with renewable energy consumption close to 100%.
Algeria, Libya, Seychelles, Egypt, South Africa, on the far left, are low performers in renewable energy consumption, with percentages close to zero.
High Performers/Low Performers
High Performers: Countries in the dark blue cluster are predominantly East and Central African nations. These countries exhibit significantly higher reliance on renewable energy sources.
Low Performers: The orange cluster consists of North African countries and others that have lower shares of renewable energy consumption, likely due to high reliance on non-renewable energy sources like oil and gas.
Cluster Assignments
The chart categorizes countries into five clusters, which group nations with similar renewable energy consumption characteristics:
i)Cluster 3 (Yellow): Countries like Algeria, Seychelles, and Libya have extremely low renewable energy consumption, falling under the 0-20% range.
ii)Cluster 2 (Orange): This cluster includes countries like Angola, Ghana, and Kenya, with significant reliance on renewable energy sources. Their consumption rates fall between 60-75%.
iii)Cluster 1 (Purple): Countries like Lesotho, South Sudan, and Botswana fall into this cluster, with moderate renewable energy consumption (25-50%)
iv)Cluster 0 (Dark Blue): Countries like Congo (Dem. Rep.), Uganda, and Ethiopia dominate this cluster with the highest levels of renewable energy consumption (76-100%).
Outliers
South Africa and Egypt stand out as large economies that are underperforming in terms of renewable energy consumption.
Seychelles, a small island nation, also has very low renewable energy use, which is notable compared to other small countries.
B. Investment Opportunity Identification¶
1. Renewable Energy Consumption(%) vs. CAGR (2021)¶
# Create a scatter plot
fig = px.scatter(df3, x='Renewable energy consumption (% of total final energy consumption)',
y='CAGR (1990-2021)',
trendline='ols', # Add a linear regression trendline
hover_data=['Country Name'], # Show country name on hover
title='Renewable Energy Consumption vs. CAGR')
# Customize the plot as needed
fig.update_layout(xaxis_title='Renewable Energy Consumption (%Total Final)-2021 ',
yaxis_title='CAGR (1990-2021)')
# Show the plot
fig.show()
Overall Observation: The scatter plot illustrates the relationship between renewable energy consumption (%Total Final) in 2021 and the Compound Annual Growth Rate (CAGR) for the period 1990-2021.
Key Findings: Weak Positive Correlation: There appears to be a weak positive correlation between renewable energy consumption and CAGR. This suggests that countries with higher renewable energy consumption in 2021 tend to have slightly higher CAGRs, but the relationship is not strong.Data Dispersion: The data points are relatively dispersed, indicating that other factors besides renewable energy consumption in 2021 influence the CAGR.
Outliers: A few outliers can be observed, suggesting that some countries may have experienced significant fluctuations in renewable energy consumption during the period, leading to unusual CAGR values.
2. Risk-reward Matrix using FDI/GDP as a proxy for investment attractiveness¶
# Create a scatter plot with hover information
fig = px.scatter(df3, x='FDI/GDP (%)', y='CAGR (1990-2021)',
hover_data=['Country Name'], # Show country name on hover
title='Risk-Reward Matrix')
# Customize the plot layout
fig.update_layout(xaxis_title='FDI/GDP (Investment Attractiveness)',
yaxis_title='CAGR (Potential Reward)')
# Add reference lines
fig.add_hline(y=0, line_color='red', line_dash='dash', annotation_text="Zero Growth")
fig.add_vline(x=df3['FDI/GDP (%)'].mean(), line_color='red', line_dash='dash',
annotation_text=f"Average FDI/GDP ({df3['FDI/GDP (%)'].mean():.2f})")
# Save as an interactive HTML file
fig.write_html("risk-reward matrix.html")
# Show the interactive plot
fig.show()
Overall Observation:This chart plots the relationship between the Compound Annual Growth Rate (CAGR) of renewable energy from 1990 to 2021 (y-axis) and the ratio of Foreign Direct Investment (FDI) to Gross Domestic Product (GDP) as a measure of investment attractiveness (x-axis).
Key Findings Growth vs. Investment: Most data points are concentrated below the zero growth line, suggesting a general decline in renewable energy consumption over the period despite varying levels of investment attractiveness.High-Risk, Low Reward: Regions left of the average FDI/GDP line, especially those in the negative growth area, may represent high-risk, low-reward investment opportunities.
Potential Opportunities: Spots above the zero line and to the right of the average FDI/GDP line could indicate regions where renewable energy consumption is growing, possibly representing better investment opportunities.
3. Correlation between FDI/GDP and Renewable Energy Consumption¶
#Calculate correlation between FDI/GDP and renewable energy percentage
correlation = df3['FDI/GDP (%)'].corr(df3['Renewable energy consumption (% of total final energy consumption)'])
print(f"Correlation between FDI/GDP and renewable energy percentage: {correlation}")
Correlation between FDI/GDP and renewable energy percentage: 0.01494076407871146
4. Correlation between FDI/GDP, CAGR and Renewable Energy Consumption¶
df3 = df3.rename(columns={
'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy Consumption',
})
corr_matrix = df3[['CAGR (1990-2021)', 'Renewable Energy Consumption', 'FDI/GDP (%)']].corr()
# Create the interactive heatmap
fig = px.imshow(
corr_matrix, # Data source
x=corr_matrix.columns, # Column labels (variable names)
y=corr_matrix.columns, # Row labels (reversed for readability)
text_auto=True, # Display correlation values on the chart
zmin=-1, # Minimum color value for the colormap
zmax=1, # Maximum color value for the colormap
title='Correlation Heatmap',
)
# Customize color scale and colorbar
fig.update_traces(colorscale='RdBu_r') # Use a red-blue colormap for positive/negative correlations
fig.update_layout(coloraxis=dict(colorbar=dict(title="Correlation Coefficient"))) # Customize colorbar
# Customize appearance
fig.update_layout(
width=800, # Increase figure width
height=600, # Increase figure height
xaxis_title_font_size=12, # Increase font size for x-axis title
yaxis_title_font_size=12, # Increase font size for y-axis title
font=dict(size=14), # Increase overall font size for text and labels
title_font=dict(size=20), # Increase font size for the title
title_x=0.5, # Center the title
margin=dict(l=80, r=80, t=100, b=80), # Adjust margins for better spacing
xaxis=dict(tickangle=-45), # Rotate x-axis labels for better readability
)
# Show the interactive heatmap
fig.show()
Overall Observation:This heatmap visualizes the correlation coefficients between different variables: FDI/GDP, Renewable Energy Consumption, and CAGR of Renewable Energy from 1990 to 2021.
Key Findings CAGR and Renewable Energy Consumption: A moderate positive correlation (0.6088) suggests that as CAGR increases, renewable energy consumption also tends to increase.FDI/GDP and Renewable Energy Consumption: A negligible correlation (0.0149) between these variables implies almost no linear relationship, suggesting that other factors might influence the renewable energy consumption independent of its current level.
CAGR and FDI/GDP: A weak negative correlation (-0.0148) indicates that higher FDI/GDP ratios are slightly associated with lower growth rates in renewable energy, though the relationship is not strong.
C. Sustainable Development Goal 7 Alignment¶
1. Correlation Analysis¶
df2 = df2.rename(columns={
'Country Name': 'Country',
'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy Consumption',
'Renewable Capacity(Watts/capita)': 'Renewable Capacity',
'Renewable Support(USD-M)': 'Renewable Support',
'Energy Intensity Level(MJ_PER_GDP_CON_PPP_USD)': 'Energy Intensity',
' Clean Energy (%)': 'Clean Energy (%)',
'Elec Access (%)': 'Electricity Access (%)'})
# Function to compute correlations for a specific year
def compute_correlations(year):
year_data = df2[df2['Year'] == year]
return year_data.corr(method='pearson', numeric_only=True)['Renewable Energy Consumption'].sort_values(ascending=False)
# Compute correlations for the most recent year
latest_year = df2['Year'].max()
correlations = compute_correlations(latest_year)
print(f"Correlations with Renewable Energy Consumption (Year {latest_year}):")
print(correlations)
# Visualize correlations
plt.figure(figsize=(10, 5))
correlations.plot(kind='bar')
plt.title(f'Correlation with Renewable Energy Consumption (Year {latest_year})')
plt.ylabel('Correlation Coefficient')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Correlations with Renewable Energy Consumption (Year 2021): Renewable Energy Consumption 1.000000 Energy Intensity 0.546470 Renewable Support 0.117629 Renewable Capacity -0.259934 Electricity Access (%) -0.626136 Clean Energy (%) -0.675254 Year NaN Name: Renewable Energy Consumption, dtype: float64
Overall Observation:This charts shows the correlations of the different SDG 7 indicators with the Renewable Energy Consumption in 2021.
Key Findings: Energy Intensity (0.546470): Has a moderate positive correlation suggesting that countries with higher renewable energy consumption tend to have higher energy intensityRenewable Support (0.117629): Has a weak positive correlation implying a slight tendency for countries with more renewable support to have higher renewable energy consumption
Renewable Capacity (-0.259934): Has a weak negative correlation counterintuitively suggesting that countries with higher renewable capacity tend to have slightly lower renewable energy consumption
Electricity Access (%) (-0.626136): Has a moderate to strong negative correlation suggesting that countries with higher electricity access tend to have lower renewable energy consumption
Clean Energy (%) (-0.675254): Has a strong negative correlation indicating that countries with higher clean energy access tend to have lower renewable energy consumption
2. Composite Score for SDG 7 Progress¶
# Select indicators for composite score
indicators = ['Renewable Energy Consumption', 'Renewable Capacity', 'Clean Energy (%)', 'Electricity Access (%)', 'Renewable Support','Energy Intensity']
# Function to normalize data
def normalize(series):
return (series - series.min()) / (series.max() - series.min())
# Create composite score for the most recent year
latest_year = df2['Year'].max()
latest_data = df2[df2['Year'] == latest_year].copy() # Create a full copy of the data
# Normalize indicators and create composite score
normalized_indicators = []
for indicator in indicators:
if indicator in latest_data.columns:
latest_data[f'{indicator}_normalized'] = normalize(latest_data[indicator])
normalized_indicators.append(f'{indicator}_normalized')
else:
print(f"Warning: {indicator} not found in the dataframe. Skipping this indicator.")
if normalized_indicators:
latest_data['Composite_Score'] = latest_data[normalized_indicators].mean(axis=1)
else:
print("Error: No indicators available for composite score calculation.")
exit()
# Assuming you have the composite score calculated in latest_data['Composite_Score']
latest_data.sort_values(by='Composite_Score', ascending=False, inplace=True)
plt.figure(figsize=(12, 6))
plt.bar(latest_data['Country'], latest_data['Composite_Score'])
plt.xlabel('Country')
plt.ylabel('Composite Score')
plt.title('Composite Score for SDG 7 Indicators in Renewable Energy Adoption')
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
plt.show()
Overall Observation:This bar chart shows the composite score for SDG 7 indicators in renewable energy adoption across various African countries. The scores range from about 0.1 to 0.65, with Gabon and South Africa leading the pack with scores above 0.6.
Key Findings: i) There's significant variation in renewable energy adoption across African countries, indicating uneven progress towards SDG 7 goals.ii) Gabon and South Africa are clear leaders, suggesting they have more developed renewable energy sectors or policies.
iii) Many countries fall in the middle range (0.3-0.5), showing moderate progress.
iv) Some countries like South Sudan have very low scores, indicating significant challenges in renewable energy adoption.
v) The overall scores are relatively low (mostly below 0.5), suggesting there's substantial room for improvement across the continent in achieving SDG 7 targets.
3. Countries That Have Made Significant Progress¶
# Calculate progress over time
first_year = df2['Year'].min()
progress_df2 = df2[df2['Year'].isin([first_year, latest_year])].pivot(index='Country', columns='Year', values='Renewable Energy Consumption')
progress_df2['Progress'] = progress_df2[latest_year] - progress_df2[first_year]
# Merge progress with latest data
analysis_df2 = pd.merge(latest_data, progress_df2['Progress'], on='Country')
# Identify top performers (top 10% in both composite score and progress)
composite_threshold = analysis_df2['Composite_Score'].quantile(0.9)
progress_threshold = analysis_df2['Progress'].quantile(0.9)
top_performers = analysis_df2[(analysis_df2['Composite_Score'] >= composite_threshold) &
(analysis_df2['Progress'] >= progress_threshold)]
print("\nTop Performing Countries:")
print(top_performers[['Country', 'Composite_Score', 'Progress']])
Top Performing Countries: Country Composite_Score Progress 0 Gabon 0.650817 18.5 4 Zimbabwe 0.494736 12.9 5 Eswatini 0.473948 5.3
4. Characteristics of Top Performing Countries¶
a. Renewable Energy Consumption¶
# Compare top performers with others
analysis_df2['Is_Top_Performer'] = analysis_df2['Country'].isin(top_performers['Country'])
# Example: Compare Renewable Capacity
plt.figure(figsize=(10, 5))
sns.boxplot(x='Is_Top_Performer', y='Renewable Energy Consumption', data=analysis_df2)
plt.title('Renewable Energy Consumption: Top Performers vs Others')
plt.show()
# Statistical test
top_capacity = analysis_df2[analysis_df2['Is_Top_Performer']]['Renewable Energy Consumption']
others_capacity = analysis_df2[~analysis_df2['Is_Top_Performer']]['Renewable Energy Consumption']
t_stat, p_value = stats.ttest_ind(top_capacity, others_capacity)
print(f"\nT-test for Renewable Energy Consumption (Top Performers vs Others):")
print(f"T-statistic: {t_stat}, p-value: {p_value}")
T-test for Renewable Energy Consumption (Top Performers vs Others): T-statistic: 1.3838594585609165, p-value: 0.17254826982701596
Overall Observation: This box plot compares renewable energy consumption between top performers (True) and others (False). It includes a t-test result for the difference between these groups.
Key Findings: i) Top performers have a higher median renewable energy consumption compared to others.ii) There's considerable overlap in the distributions, suggesting variability within each group.
iii) The t-test result (p-value = 0.1725) indicates that the difference between the two groups is not statistically significant at the conventional 0.05 level.
iv) Both groups show wide ranges of renewable energy consumption, from near 0% to 100%.
v) The top performers seem to have a slightly smaller range and higher minimum values, suggesting more consistent adoption of renewable energy.
b. Renewable Energy Capacity¶
# Compare top performers with others
analysis_df2['Is_Top_Performer'] = analysis_df2['Country'].isin(top_performers['Country'])
# Example: Compare Renewable Capacity
plt.figure(figsize=(10, 5))
sns.boxplot(x='Is_Top_Performer', y='Renewable Capacity', data=analysis_df2)
plt.title('Renewable Capacity: Top Performers vs Others')
plt.show()
# Statistical test
top_capacity = analysis_df2[analysis_df2['Is_Top_Performer']]['Renewable Capacity']
others_capacity = analysis_df2[~analysis_df2['Is_Top_Performer']]['Renewable Capacity']
t_stat, p_value = stats.ttest_ind(top_capacity, others_capacity)
print(f"\nT-test for Renewable Capacity (Top Performers vs Others):")
print(f"T-statistic: {t_stat}, p-value: {p_value}")
T-test for Renewable Capacity (Top Performers vs Others): T-statistic: 2.783349819800951, p-value: 0.00757348175122658
Overall Observation:This box plot compares the renewable capacity between top performers (True) and others (False).
Key Findings: i) Top performers have significantly higher renewable capacity than others, with their median and entire box plot range being higher.ii) There's more variation in renewable capacity among top performers, as indicated by their larger box and longer whiskers.
iii) The non-top performers have several high outliers, suggesting some entities in this group have unexpectedly high renewable capacity.
iv) The t-test results (t-statistic: 2.7833, p-value: 0.00757) indicate a statistically significant difference between the two groups, with a very low p-value suggesting strong evidence against the null hypothesis of no difference.
c. Access to Clean Energy¶
# Compare top performers with others
analysis_df2['Is_Top_Performer'] = analysis_df2['Country'].isin(top_performers['Country'])
# Example: Compare Renewable Capacity
plt.figure(figsize=(10, 5))
sns.boxplot(x='Is_Top_Performer', y='Clean Energy (%)', data=analysis_df2)
plt.title('Clean Energy (%): Top Performers vs Others')
plt.show()
# Statistical test
top_capacity = analysis_df2[analysis_df2['Is_Top_Performer']]['Clean Energy (%)']
others_capacity = analysis_df2[~analysis_df2['Is_Top_Performer']]['Clean Energy (%)']
t_stat, p_value = stats.ttest_ind(top_capacity, others_capacity)
print(f"\nT-test for Clean Energy (%) (Top Performers vs Others):")
print(f"T-statistic: {t_stat}, p-value: {p_value}")
T-test for Clean Energy (%) (Top Performers vs Others): T-statistic: nan, p-value: nan
Overall Observation:This box plot compares the percentage of clean energy between top performers (True) and others (False).
Key Findings: i) Top performers have a notably higher median and overall range of clean energy percentages compared to others.ii) There's considerable overlap in the ranges, indicating some non-top performers may have clean energy percentages comparable to top performers.
iii) Both groups show a wide range of clean energy percentages, suggesting significant variation within each group.
iv) The t-test results are missing (shown as "nan" for both t-statistic and p-value), so we cannot draw conclusions about statistical significance.
d. Access to Electricity¶
# Compare top performers with others
analysis_df2['Is_Top_Performer'] = analysis_df2['Country'].isin(top_performers['Country'])
# Example: Compare Renewable Capacity
plt.figure(figsize=(10, 5))
sns.boxplot(x='Is_Top_Performer', y='Electricity Access (%)', data=analysis_df2)
plt.title('Electricity Access (%): Top Performers vs Others')
plt.show()
# Statistical test
top_capacity = analysis_df2[analysis_df2['Is_Top_Performer']]['Electricity Access (%)']
others_capacity = analysis_df2[~analysis_df2['Is_Top_Performer']]['Electricity Access (%)']
t_stat, p_value = stats.ttest_ind(top_capacity, others_capacity)
print(f"\nT-test for Electricity Access (%) (Top Performers vs Others):")
print(f"T-statistic: {t_stat}, p-value: {p_value}")
T-test for Electricity Access (%) (Top Performers vs Others): T-statistic: 1.2344626640083942, p-value: 0.2228009622887451
Overall Observation:This box plot compares the percentage of electricity access between top performers (True) and others (False).
Key Findings: i) Top performers generally have higher electricity access percentages, with a higher median and 75th percentile.ii) There's considerable overlap between the two groups, especially in the lower ranges.
iii) Non-top performers show a wider range of electricity access percentages, indicating more variability in this group.
iv) The t-test results (t-statistic: 1.2344, p-value: 0.2228) suggest that while there's a difference, it may not be statistically significant at conventional levels (p < 0.05).
e. Energy Intensity¶
# Compare top performers with others
analysis_df2['Is_Top_Performer'] = analysis_df2['Country'].isin(top_performers['Country'])
# Example: Compare Renewable Capacity
plt.figure(figsize=(10, 5))
sns.boxplot(x='Is_Top_Performer', y='Energy Intensity', data=analysis_df2)
plt.title('Energy Intensity (%): Top Performers vs Others')
plt.show()
# Statistical test
top_capacity = analysis_df2[analysis_df2['Is_Top_Performer']]['Energy Intensity']
others_capacity = analysis_df2[~analysis_df2['Is_Top_Performer']]['Energy Intensity']
t_stat, p_value = stats.ttest_ind(top_capacity, others_capacity)
print(f"\nT-test for Energy Intensity (Top Performers vs Others):")
print(f"T-statistic: {t_stat}, p-value: {p_value}")
T-test for Energy Intensity (Top Performers vs Others): T-statistic: 1.5377336561449886, p-value: 0.13041863289148292
Overall Observation:
Key Findings: This box plot compares energy intensity percentages between top performers (True) and others (False). i) Top performers have a slightly higher median energy intensity compared to others.ii) There's considerable overlap in the interquartile ranges, suggesting the difference between groups may not be substantial.
iii) Non-top performers have several high outliers, indicating some entities in this group have unusually high energy intensity.
iv) The t-test results (t-statistic: 1.5377, p-value: 0.1304) suggest that the difference in energy intensity between the two groups is not statistically significant at conventional levels.
f. Renewable Support¶
# Compare top performers with others
analysis_df2['Is_Top_Performer'] = analysis_df2['Country'].isin(top_performers['Country'])
# Example: Compare Renewable Capacity
plt.figure(figsize=(10, 5))
sns.boxplot(x='Is_Top_Performer', y='Renewable Support', data=analysis_df2)
plt.title('Renewable Support: Top Performers vs Others')
plt.show()
# Statistical test
top_capacity = analysis_df2[analysis_df2['Is_Top_Performer']]['Renewable Support']
others_capacity = analysis_df2[~analysis_df2['Is_Top_Performer']]['Renewable Support']
t_stat, p_value = stats.ttest_ind(top_capacity, others_capacity)
print(f"\nT-test for Renewable Support (Top Performers vs Others):")
print(f"T-statistic: {t_stat}, p-value: {p_value}")
T-test for Renewable Support (Top Performers vs Others): T-statistic: -0.6250798682680001, p-value: 0.5347611347854928
Overall Observation: This box plot compares renewable support between top performers (True) and others (False)
Key Findings: i) Surprisingly, non-top performers show higher median renewable support and a wider range compared to top performers.ii) Top performers have a much narrower range of renewable support values, suggesting more consistency within this group.
iii) Non-top performers have several high outliers, indicating some entities in this group provide exceptionally high renewable support.
iv) The t-test results (t-statistic: -0.6250, p-value: 0.5347) indicate that the difference in renewable support between the two groups is not statistically significant.
5. Time Series Analysis for Top Performing Countries¶
a. Gabon¶
# Select a top performer for demonstration
example_country = top_performers['Country'].iloc[0]
country_data = df2[df2['Country'] == example_country]
plt.figure(figsize=(12, 6))
plt.plot(country_data['Year'], country_data['Renewable Energy Consumption'])
plt.title(f'Renewable Energy Consumption Over Time: {example_country}')
plt.xlabel('Year')
plt.ylabel('Renewable Energy Consumption')
plt.show()
b. Zimbabwe¶
# Select a top performer for demonstration
example_country = top_performers['Country'].iloc[1]
country_data = df2[df2['Country'] == example_country]
plt.figure(figsize=(12, 6))
plt.plot(country_data['Year'], country_data['Renewable Energy Consumption'])
plt.title(f'Renewable Energy Consumption Over Time: {example_country}')
plt.xlabel('Year')
plt.ylabel('Renewable Energy Consumption')
plt.show()
c. Eswatini¶
# Select a top performer for demonstration
example_country = top_performers['Country'].iloc[2]
country_data = df2[df2['Country'] == example_country]
plt.figure(figsize=(12, 6))
plt.plot(country_data['Year'], country_data['Renewable Energy Consumption'])
plt.title(f'Renewable Energy Consumption Over Time: {example_country}')
plt.xlabel('Year')
plt.ylabel('Renewable Energy Consumption')
plt.show()
The Top Three Performers¶
# Get the top three performers
top_three_countries = top_performers['Country'].iloc[:3]
# Initialize a figure for plotting
plt.figure(figsize=(12, 6))
# Loop through the top three countries and plot their data
for country in top_three_countries:
country_data = df2[df2['Country'] == country]
plt.plot(country_data['Year'], country_data['Renewable Energy Consumption'], label=country)
# Add title and labels
plt.title('Renewable Energy Consumption Over Time: Top 3 Countries')
plt.xlabel('Year')
plt.ylabel('Renewable Energy Consumption')
plt.legend(title='Country')
# Show the plot
plt.show()
Overall Observation:The chart displays a line graph comparing the renewable energy consumption of Gabon, Zimbabwe, and Eswatini over the years 2000 to 2020.
Key Findings: Gabon's Dominance: Gabon consistently maintains the highest level of renewable energy consumption throughout the period, with a significant increase from 2015 onwards.Zimbabwe's Fluctuations: Zimbabwe's renewable energy consumption fluctuates over time, with peaks in 2005 and 2015-2016 followed by declines.
Eswatini's Steady Growth: Eswatini exhibits a relatively steady growth in renewable energy consumption, with a gradual increase throughout the period.
D. Economic Impact Assessment¶
1. Correlation Analysis between Renewable Energy Consumption and GDP Growth Rate¶
df1 = df1.rename(columns={
'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy Consumption',
'FDI/GDP (%)': 'FDI/GDP',
})
def correlation_analysis(df1):
# Calculate correlation while ignoring missing values
correlation = df1['Renewable Energy Consumption'].corr(df1['GDP Growth Rate'], method='pearson', min_periods=1)
# Plot the scatterplot, automatically skipping missing values
plt.figure(figsize=(10, 6))
sns.scatterplot(x='Renewable Energy Consumption', y='GDP Growth Rate', data=df1)
# Title with the correlation value
plt.title(f'Correlation between Renewable Energy % and GDP Growth Rate: {correlation:.2f}')
# Display the plot
plt.show()
# Call the function
correlation_analysis(df1)
Overall Observation: This scatter plot shows the relationship between renewable energy consumption (x-axis) and GDP growth rate (y-axis). The correlation coefficient is 0.03, indicating a very weak positive correlation.
Key Findings: i) There's virtually no linear relationship between renewable energy consumption and GDP growth rate (correlation of 0.03).ii) GDP growth rates vary widely, from about -50% to over 300%, regardless of renewable energy consumption.
iii) Most data points cluster around lower GDP growth rates (0-50%) across all levels of renewable energy consumption.
iv) There are some extreme outliers in GDP growth, particularly on the positive side.
v) Renewable energy consumption ranges from 0% to 100%, showing wide variation among the data points.
2. Regression Analysis¶
def regression_analysis(df1):
# Create lagged variables
for lag in range(1, 4):
df1[f'renewable_energy_consumption_lag{lag}'] = df1.groupby('Country Name')['Renewable Energy Consumption'].shift(lag)
df1[f'FDI/GDP_lag{lag}'] = df1.groupby('Country Name')['FDI/GDP'].shift(lag)
# Drop rows with missing values
df1.dropna(inplace=True)
# Prepare the data for regression
X = df1[['renewable_energy_consumption_lag1', 'renewable_energy_consumption_lag2', 'renewable_energy_consumption_lag3',
'FDI/GDP_lag1', 'FDI/GDP_lag2', 'FDI/GDP_lag3']]
y = df1['GDP Growth Rate']
# Add a constant to the independent variables
X = sm.add_constant(X)
# Fit the model
model = sm.OLS(y, X).fit()
# Print the summary
print(model.summary())
# Call the function
regression_analysis(df1)
OLS Regression Results ============================================================================== Dep. Variable: GDP Growth Rate R-squared: 0.039 Model: OLS Adj. R-squared: 0.035 Method: Least Squares F-statistic: 8.895 Date: Tue, 12 Nov 2024 Prob (F-statistic): 1.55e-09 Time: 13:21:27 Log-Likelihood: -5688.6 No. Observations: 1322 AIC: 1.139e+04 Df Residuals: 1315 BIC: 1.143e+04 Df Model: 6 Covariance Type: nonrobust ===================================================================================================== coef std err t P>|t| [0.025 0.975] ----------------------------------------------------------------------------------------------------- const 3.6284 1.172 3.097 0.002 1.330 5.927 renewable_energy_consumption_lag1 -0.2877 0.216 -1.333 0.183 -0.711 0.136 renewable_energy_consumption_lag2 0.1786 0.302 0.591 0.555 -0.414 0.771 renewable_energy_consumption_lag3 0.1523 0.216 0.706 0.480 -0.271 0.575 FDI/GDP_lag1 0.2458 0.060 4.100 0.000 0.128 0.363 FDI/GDP_lag2 0.0039 0.064 0.061 0.952 -0.121 0.129 FDI/GDP_lag3 0.1363 0.060 2.277 0.023 0.019 0.254 ============================================================================== Omnibus: 1319.850 Durbin-Watson: 1.939 Prob(Omnibus): 0.000 Jarque-Bera (JB): 213605.145 Skew: 4.262 Prob(JB): 0.00 Kurtosis: 64.686 Cond. No. 283. ============================================================================== Notes: [1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
Overall Observation:This table presents the results of an Ordinary Least Squares (OLS) regression analysis, with GDP Growth Rate as the dependent variable and lagged values of renewable energy consumption and FDI/GDP as independent variables.
Key Findings: i) The model has a very low R-squared (0.046), indicating it explains only 4.6% of the variation in GDP growth rates.ii) Most coefficients are not statistically significant at the 5% level, except for FDI/GDP_lag1 and FDI/GDP_lag3.
iii) The F-statistic is significant (p-value < 0.05), suggesting the model as a whole has some explanatory power, despite the low R-squared.
iv) There's a potential negative relationship between renewable energy consumption and GDP growth in the short term (lag1), but it's not statistically significant.
v) FDI/GDP seems to have a more consistent positive relationship with GDP growth, especially at lags 1 and 3.
# Prepare the data for fitting the model
X = df1['Renewable Energy Consumption']
y = df1['GDP Growth Rate']
# Add a constant to the predictor variable (required for statsmodels)
X = sm.add_constant(X)
# Fit the model
model = sm.OLS(y, X).fit()
# Plot the scatter plot
plt.figure(figsize=(10, 6))
plt.scatter(df1['Renewable Energy Consumption'], df1['GDP Growth Rate'], label='Data Points')
# Plot the fitted line
plt.plot(df1['Renewable Energy Consumption'], model.fittedvalues, color='red', label='Fitted Line')
# Add labels and title
plt.xlabel('Renewable Energy Consumption')
plt.ylabel('GDP Growth Rate')
plt.title('Regression Analysis: Renewable Energy Consumption vs. GDP Growth Rate')
plt.legend()
# Show the plot
plt.show()
Overall Observation:This scatter plot shows the relationship between renewable energy consumption and GDP growth rate, with a fitted regression line.
Key Findings: i) The regression line is nearly horizontal, confirming the weak correlation observed in Image 2.ii) There's high variability in GDP growth rates across all levels of renewable energy consumption.
iii) Most data points cluster around lower GDP growth rates, with a few extreme positive outliers.
iv) The fitted line suggests a slight positive relationship, but the effect appears minimal
v) The plot reinforces that factors other than renewable energy consumption likely have more significant impacts on GDP growth rates.
3. Case Studies of Countries with Significant Renewable Energy Growth¶
def select_case_studies(df1):
# Calculate the growth rate of renewable energy percentage
df1['Renewable Energy Growth'] = df1.groupby('Country Name')['Renewable Energy Consumption'].pct_change()
# Drop rows where Renewable Energy Growth is NaN
df1.dropna(subset=['Renewable Energy Growth'], inplace=True)
# Calculate the average growth rate for each country, skipping missing values
avg_growth = df1.groupby('Country Name')['Renewable Energy Growth'].mean().sort_values(ascending=False)
# Select top 5 countries with the highest average growth
top_countries = avg_growth.head()
# Display the result
print("Top 5 countries with significant renewable energy growth:")
print(top_countries)
# Return the list of top countries
return top_countries.index.tolist()
# Call the function
selected_countries = select_case_studies(df1)
Top 5 countries with significant renewable energy growth: Country Name Libya 0.019200 Gabon 0.010612 Zimbabwe 0.008969 Eritrea 0.004330 Seychelles 0.003791 Name: Renewable Energy Growth, dtype: float64
# Plot renewable energy consumption over time for case study countries
plt.figure(figsize=(12, 6))
for country in selected_countries:
country_data = df1[df1['Country Name'] == country]
plt.plot(country_data['Year'], country_data['Renewable Energy Consumption'], label=country)
plt.title('Renewable Energy Consumption Over Time for Case Study Countries')
plt.xlabel('Year')
plt.ylabel('Renewable Energy Consumption(%)')
plt.legend()
plt.show()
Overall Observation: The chart displays a line graph comparing the renewable energy consumption of five African countries: Zimbabwe, Gabon, Congo, Republic, Eswatini, and Liberia, over the years 1995 to 2020.
Key Findings: Varied Trends: Each country exhibits a unique pattern of renewable energy consumption.Gabon and Zimbabwe: Gabon and Zimbabwe demonstrate a general upward trend, with periods of growth and decline.
Congo, Republic and Eswatini: Congo, Republic and Eswatini show more fluctuations, with periods of both increase and decrease.
Liberia:Liberia's renewable energy consumption is relatively stable, with a slight increase in recent years.
E. Regional Cooperation Framework¶
1. Hierarchical Clustering of Countries Based on Renewable Energy Consumption, Growth Rate and GDP/Capita¶
# Display the first few rows of the data
print(df3.head())
Country Name \ 0 Algeria 1 Angola 2 Benin 3 Botswana 4 Burkina Faso Renewable energy consumption (% of total final energy consumption) \ 0 0.1 1 52.9 2 54.5 3 27.4 4 71.2 ISO Code CAGR (1990-2021) CAGR (2016-2021) FDI/GDP (%) GDP/Capita 0 DZA -0.022111 0.000000 0.467 11000 1 AGO -0.010027 0.019206 -6.550 5910 2 BEN -0.017329 0.037213 1.960 3320 3 BWA -0.018576 0.005189 -1.700 14900 4 BFA -0.006185 -0.015796 -0.407 2180
df3 = df3.rename(columns={
'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy Consumption',
'CAGR (2016-2021)': 'Renewable Growth Rate',
'GDP/Capita':'GDP per Capita'
})
# Separate features for clustering
features = ['Renewable Energy Consumption', 'Renewable Growth Rate', 'GDP per Capita']
X = df3[features]
# Standardize the features
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
# Perform hierarchical clustering
n_clusters =4 # Adjust based on your needs
clustering = AgglomerativeClustering(n_clusters=n_clusters)
df3['Cluster'] = clustering.fit_predict(X_scaled)
# Create an interactive scatter plot
fig = px.scatter(df3,
x='Renewable Energy Consumption',
y='Renewable Growth Rate',
color='Cluster',
size='GDP per Capita',
hover_name='Country Name',
title='Country Clusters based on Renewable Energy and Growth',
labels={'Renewable Energy Consumption': 'Renewable Energy %',
'Renewable Growth Rate': 'Growth Rate'})
# Customize the color scale
fig.update_traces(marker=dict(opacity=0.7),
selector=dict(mode='markers'))
# Update layout for better interactivity
fig.update_layout(legend_title_text='Cluster',
xaxis=dict(title='Renewable Energy Consumption (%)'),
yaxis=dict(title='Growth Rate'),
coloraxis_colorbar=dict(title="Cluster"))
# Save as an interactive HTML file
fig.write_html("country_clusters.html")
# Show the interactive plot
fig.show()
# Print a list of clusters with the countries assigned to each
clustered_countries = df3.groupby('Cluster')['Country Name'].apply(list)
print("Countries in each cluster:")
for cluster, countries in clustered_countries.items():
print(f"Cluster {cluster}: {countries}")
Countries in each cluster: Cluster 0: ['Algeria', 'Botswana', 'Cape Verde', 'Egypt', 'Equatorial Guinea', 'Libya', 'Mauritius', 'Morocco', 'Namibia', 'Seychelles', 'South Africa', 'Tunisia'] Cluster 1: ['Angola', 'Benin', 'Congo, Rep.', "Cote d'Ivoire", 'Djibouti', 'Eswatini', 'Gabon', 'Gambia', 'Ghana', 'Kenya', 'Sao Tome and Principe', 'Senegal', 'South Sudan', 'Sudan'] Cluster 2: ['Comoros', 'Lesotho', 'Mauritania'] Cluster 3: ['Burkina Faso', 'Burundi', 'Cameroon', 'Central African Republic', 'Chad', 'Congo, Dem. Rep.', 'Eritrea', 'Ethiopia', 'Guinea', 'Guinea-Bissau', 'Liberia', 'Madagascar', 'Malawi', 'Mali', 'Mozambique', 'Niger', 'Nigeria', 'Rwanda', 'Sierra Leone', 'Somalia', 'Tanzania', 'Togo', 'Uganda', 'Zambia', 'Zimbabwe']
Overall Observation: The chart displays a scatter plot clustering African countries based on their renewable energy consumption and growth rate. The x-axis represents renewable energy consumption, the y-axis represents growth rate, and the color of each dot indicates the cluster to which the country belongs.
Key Findings: Cluster 3:Countries in this cluster have relatively high renewable energy consumption and low growth rates.
Cluster 2:
Countries in this cluster have moderate renewable energy consumption and growth rates.
Cluster 1:
Countries in this cluster have low renewable energy consumption and low growth rates.
Cluster 0:
Countries in this cluster have low renewable energy consumption but relatively high growth rates.
2. Potential Region Leaders in Renewable Energy Adoption¶
# Function to identify the leader in each cluster
def identify_leader(cluster_df3):
# Adjust the scoring method based on specific priorities
cluster_df3['Score'] = (
cluster_df3['Renewable Energy Consumption'] +
cluster_df3['Renewable Growth Rate'] * 10 +
cluster_df3['GDP per Capita'] / 1000
)
return cluster_df3.loc[cluster_df3['Score'].idxmax()]
# Identify leaders for each cluster
leaders = df3.groupby('Cluster').apply(identify_leader)
print("\nPotential Regional Leaders:")
print(leaders[['Country Name', 'Renewable Energy Consumption', 'Renewable Growth Rate', 'GDP per Capita']])
# Create an interactive scatter plot with regional leaders highlighted
fig = px.scatter(df3,
x='Renewable Energy Consumption',
y='Renewable Growth Rate',
color='Cluster',
size='GDP per Capita',
hover_name='Country Name',
title='Country Clusters with Regional Leaders',
labels={'Renewable Energy Consumption': 'Renewable Energy (%)',
'Renewable Growth Rate': 'Growth Rate'})
# Highlight the regional leaders
fig.add_trace(px.scatter(leaders,
x='Renewable Energy Consumption',
y='Renewable Growth Rate',
size='GDP per Capita',
color_discrete_sequence=['red'],
hover_name='Country Name',
symbol_sequence=['star']).data[0])
# Update layout for better interactivity and clarity
fig.update_traces(marker=dict(opacity=0.5),
selector=dict(mode='markers'))
fig.update_layout(legend_title_text='Cluster',
xaxis=dict(title='Renewable Energy Consumption'),
yaxis=dict(title='Renewable Growth Rate'),
coloraxis_colorbar=dict(title="Cluster"),
legend=dict(itemsizing='constant'))
# Save as an interactive HTML file
fig.write_html("regional_leaders.html")
# Show the interactive plot
fig.show()
Potential Regional Leaders: Country Name Renewable Energy Consumption \ Cluster 0 Botswana 27.4 1 Gabon 91.3 2 Comoros 41.2 3 Congo, Dem. Rep. 96.3 Renewable Growth Rate GDP per Capita Cluster 0 0.005189 14900 1 0.022969 13800 2 -0.084321 3230 3 -0.001447 1070
Overall Observation:This scatter plot maps out the relationship between the percentage of renewable energy consumption and the renewable energy growth rate. Countries are color-coded by cluster, with some countries marked with stars indicating regional leaders.
Key Findings: High Consumption with Varying Growth: Some countries like Gabon and Congo, Dem. Rep. consume a high percentage of renewable energy but have starkly different growth rates.Potential Leaders: Marked by stars, these countries are notable within their clusters either for high consumption or notable growth rates.
Cluster Variation: Clusters show varying levels of renewable energy consumption and growth rates.
Economic and Renewable Correlation: Higher GDP per capita in Gabon and lower in Congo, Dem. Rep., suggesting economic factors may influence renewable initiatives.
Renewable Energy Adoption in Africa: Kenya's Case Study¶
1. Renewable Energy Consumption in Kenya (1990-2021)¶
kenya_data = df1[df1['Country Name'] == 'Kenya']
fig = go.Figure(go.Scatter(
x=kenya_data['Year'],
y=kenya_data['Renewable energy consumption (% of total final energy consumption)'],
mode='lines+markers',
name='Renewable Energy Consumption '
))
fig.update_layout(
title='Renewable Energy Consumption in Kenya 1990-2021',
xaxis_title='Year',
yaxis_title='Renewable Energy Consumption (%)',
hovermode='x'
)
Overall Observation: The line chart illustrates the trend in renewable energy consumption as a percentage of total final energy consumption in Kenya from 1990 to 2021.
Key Findings: Initial Increase: Renewable energy consumption increased steadily from 1990 to 2003, reaching a peak of around 81%.Decline and Stabilization: Following this peak, consumption declined until 2010, then stabilized at a level of approximately 70-75%.
Recent Fluctuations: In the later years, there have been minor fluctuations around this stabilized level.
2. Renewable Energy Consumption in Kenya compared with the Top Three Performing Countries in Africa 1990-2021¶
# Define a list of countries to compare with Kenya
countries_to_compare = ['Kenya', 'Gabon', 'Zimbabwe', 'Eswatini']
# Filter the DataFrame using loc for efficient selection
compare_data = df1.loc[df1['Country Name'].isin(countries_to_compare)]
traces = [] # List to store traces for each country
for country in countries_to_compare:
country_data = df1[df1['Country Name'] == country]
traces.append(go.Scatter(
x=country_data['Year'],
y=country_data['Renewable energy consumption (% of total final energy consumption)'],
mode='lines',
name=country
))
fig = go.Figure(data=traces)
fig.update_layout(
title='Renewable Energy Consumption in Kenya compared with the Top Three Countries in Africa',
xaxis_title='Year',
yaxis_title='Renewable Energy Consumption (%)',
hovermode='x'
)
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=[
dict(count=5, label="Last 5 years", step="year", stepmode="backward"),
dict(count=10, label="Last 10 years", step="year", stepmode="backward"),
dict(count=20, label="Last 20 years", step="year", stepmode="backward"),
dict(step="all")
]
),
rangeslider=dict(
visible=True
),
type="date"
)
)
Overall Observation: The line chart compares the renewable energy consumption of Kenya with the top three countries in Africa (Gabon, Zimbabwe, and Eswatini) over the period 1990-2021.
Key Findings: Kenya's Position:Gabon's Recent Surge: Gabon has experienced a significant increase in renewable energy consumption in recent years, surpassing Zimbabwe and Eswatini.
:
3. Renewable Energy Consumption for Kenya and the Top 20 Countries¶
top_countries = df1['Country Name'].value_counts().head(20).index
filtered_data = df1[df1['Country Name'].isin(top_countries)]
kenya_data = df1[df1['Country Name'] == 'Kenya']
filtered_data_updated = pd.concat([filtered_data, kenya_data])
heatmap_data= filtered_data_updated.pivot(index='Country Name', columns='Year', values='Renewable energy consumption (% of total final energy consumption)')
plt.figure(figsize=(10, 5))
sns.heatmap(heatmap_data, annot=False, cmap="viridis")
plt.title('Distribution of Renewable Energy Consumption for the Top 20 Countries and Kenya (Heatmap)')
plt.xlabel('Year')
plt.ylabel('Country Name')
plt.xticks(rotation=45)
plt.yticks(rotation=0)
plt.show()
Overall Observation: The heatmap provides a visual representation of the trends in renewable energy consumption for the top 20 countries in Africa and Kenya over the period 1990-2021. The color scale indicates the level of renewable energy consumption, with darker shades representing higher levels.
Key Findings: Varied Trends: Different countries exhibit diverse patterns of renewable energy adoption. Some countries show a steady increase over time, while others experience fluctuations or declines.Regional Differences: There are noticeable regional variations in renewable energy adoption. For example, countries in North Africa and Southern Africa tend to have lower overall levels of renewable energy consumption compared to those in Central and West Africa.
Specific Country Trends: Certain countries, such as Kenya, Mauritius, and Seychelles, demonstrate significant decline in renewable energy consumption over the years. Others, like South Sudan and Somalia, exhibit more consistent patterns.
4. Kenya's Comparison with Countries with the Lowest and Highest Renewable Energy Consumption Rates in 2021¶
# Filter data for Kenya
kenya_data = df3[df3['Country Name'] == 'Kenya']
# Get top 5 with highest and lowest consumption (assuming sorted by year)
top_5_highest = df3.nlargest(5, 'Renewable energy consumption (% of total final energy consumption)') # Use nlargest for efficient selection
top_5_lowest = df3.nsmallest(5, 'Renewable energy consumption (% of total final energy consumption)') # Use nsmallest for efficient selection
# Combine Kenya data with top 5 highest and lowest
combined_data = pd.concat([top_5_lowest, kenya_data, top_5_highest])
# Assign colors based on ranking
colors = []
for entity in combined_data['Country Name']:
if entity in top_5_lowest['Country Name'].values:
colors.append('red')
elif entity in kenya_data['Country Name'].values:
colors.append('green')
else:
colors.append('blue')
# Create the bar chart with labels
plt.figure(figsize=(16, 8))
bars = plt.bar(combined_data['Country Name'], combined_data['Renewable energy consumption (% of total final energy consumption)'], color=colors)
for bar in bars:
height = bar.get_height()
# Improved text positioning logic
text_x = bar.get_x() + bar.get_width() / 2
plt.text(text_x, height + 0.5, f'{height:.2f}', ha='center', fontsize=12, fontweight='bold')
# Set plot title, labels, and formatting
plt.title(f'Kenya and Countries with the Highest and Lowest Renewable Energy Consumption Rates in 2021', fontsize=16, fontweight='bold')
plt.xlabel('Country', fontsize=14, fontweight='bold')
plt.ylabel('Renewable Energy Consumption (%)', fontsize=14, fontweight='bold')
plt.xticks(rotation=45)
plt.grid(True, linestyle='--', alpha=0.7)
plt.tick_params(axis='both', which='major', labelsize=12, width=2)
plt.tight_layout()
plt.show()
Overall Observation
Key Findings: Kenya's Position: Kenya ranks among the moderately high countries in terms of renewable energy consumption, with a rate of 67.70%.High-Performing Countries: The countries with the highest rates (Congo, Dem. Rep., Somalia, Liberia, Gabon) all exceed 90% renewable energy consumption.
Low-Performing Countries: The countries with the lowest rates (Algeria, Seychelles, Libya, Equatorial Guinea, Egypt) have significantly lower consumption levels, with most below 10%.