Skip to content

Commit 06f05d6

Browse files
committed
Refactor data processing in pipeline.py to standardize column names for renewable and fossil fuel energy consumption. Update visualizations and report generation to reflect these changes, enhancing clarity and consistency in the analysis.
1 parent 20467b3 commit 06f05d6

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pipeline.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def fetch_world_bank_data():
5858
def process_data(df):
5959
"""Process and clean the energy data"""
6060
# Calculate year-over-year changes
61-
df['Renewable Growth'] = df.groupby('country')['Renewable energy consumption (% of total final energy consumption)'].pct_change()
61+
df['Renewable Growth'] = df.groupby('country')['Renewable energy consumption'].pct_change()
6262

6363
# Calculate energy transition score (higher renewable %, lower fossil fuel %)
6464
df['Energy Transition Score'] = (
65-
df['Renewable energy consumption (% of total final energy consumption)'] -
66-
df['Fossil fuel energy consumption (% of total)']
65+
df['Renewable energy consumption'] -
66+
df['Fossil fuel energy consumption']
6767
)
6868

6969
# Get latest data for each country
@@ -100,15 +100,16 @@ def create_visualizations(df, latest_data, regional_avg):
100100
# 1. Energy Transition Progress
101101
fig_transition = px.scatter(
102102
latest_data,
103-
x='Fossil fuel energy consumption (% of total)',
104-
y='Renewable energy consumption (% of total final energy consumption)',
105-
size='Energy use per capita (kg of oil equivalent)',
103+
x='Fossil fuel energy consumption',
104+
y='Renewable energy consumption',
105+
size='Energy use per capita',
106106
color='Region',
107107
hover_data=['country'],
108108
title='Energy Transition Progress by Country',
109109
labels={
110-
'Fossil fuel energy consumption (% of total)': 'Fossil Fuel Consumption (%)',
111-
'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy (%)'
110+
'Fossil fuel energy consumption': 'Fossil Fuel Consumption (%)',
111+
'Renewable energy consumption': 'Renewable Energy (%)',
112+
'Energy use per capita': 'Energy Use per Capita (kg of oil equivalent)'
112113
}
113114
)
114115
fig_transition.write_html('output/energy_transition.html')
@@ -117,11 +118,11 @@ def create_visualizations(df, latest_data, regional_avg):
117118
fig_regional = px.line(
118119
regional_avg,
119120
x='date',
120-
y='Renewable energy consumption (% of total final energy consumption)',
121+
y='Renewable energy consumption',
121122
color='Region',
122123
title='Regional Renewable Energy Adoption Trends',
123124
labels={
124-
'Renewable energy consumption (% of total final energy consumption)': 'Renewable Energy (%)',
125+
'Renewable energy consumption': 'Renewable Energy (%)',
125126
'date': 'Year'
126127
}
127128
)
@@ -139,11 +140,11 @@ def generate_report(latest_data, transition_file, regional_file):
139140
Key Statistics:
140141
--------------
141142
Total Countries Analyzed: {len(latest_data)}
142-
Global Average Renewable Energy Share: {latest_data['Renewable energy consumption (% of total final energy consumption)'].mean():.2f}%
143+
Global Average Renewable Energy Share: {latest_data['Renewable energy consumption'].mean():.2f}%
143144
144145
Top 5 Countries by Renewable Energy Share:
145146
----------------------------------------
146-
{latest_data.nlargest(5, 'Renewable energy consumption (% of total final energy consumption)')[['country', 'Renewable energy consumption (% of total final energy consumption)']].to_string()}
147+
{latest_data.nlargest(5, 'Renewable energy consumption')[['country', 'Renewable energy consumption']].to_string()}
147148
148149
Top 5 Countries by Energy Transition Score:
149150
----------------------------------------

0 commit comments

Comments
 (0)