Green energy is any energy type that is generated from natural resources, such as sunlight, wind or water. It often comes from renewable energy sources although there are some differences between renewable and green energy.
The key with these energy resources are that they don’t harm the environment through factors such as releasing greenhouse gases into the atmosphere.
As a source of energy, green energy often comes from renewable energy technologies such as solar energy, wind power, geothermal energy, biomass and hydroelectric power. Each of these technologies works in different ways, whether that is by taking power from the sun, as with solar panels, or using wind turbines or the flow of water to generate energy.
In order to be deemed green energy, a resource cannot produce pollution, such as is found with fossil fuels.
This means that not all sources used by the renewable energy industry are green. For example, power generation that burns organic material from sustainable forests may be renewable, but it is not necessarily green, due to the CO2 produced by the burning process itself.
The main sources are wind energy, solar power and hydroelectric power (including tidal energy, which uses ocean energy from the tides in the sea). Solar and wind power are able to be produced on a small scale at people’s homes or alternatively, they can be generated on a larger, industrial scale.
The six most common forms are as follows:
This common renewable, green energy source is usually produced using photovoltaic cells that capture sunlight and turn it into electricity. Solar power is also used to heat buildings and for hot water as well as for cooking and lighting. Solar power has now become affordable enough to be used for domestic purposes including garden lighting, although it is also used on a larger scale to power entire neighbourhoods.
Solar energy is the most abundant energy source on the planet, because the sun shines down every single day. Anywhere the sun touches could be converted into solar power.
Particularly suited to offshore and higher altitude sites, wind energy uses the power of the flow of air around the world to push turbines that then generate electricity.
Also known as hydroelectric power, this type of green energy uses the flow of water in rivers, streams, dams or elsewhere to produce energy. Hydropower can even work on a small scale using the flow of water through pipes in the home or can come from evaporation, rainfall or the tides in the oceans.
Wave and tidal power is generated using large underwater turbines. These rotate with the ebbing and flowing of the moving water to create energy. The turbines are connected to electrical generators that turn this kinetic energy into electricity, which we can use. Tidal energy is the oldest form of renewable energy. It was used by the Romans when they occupied Britain to power water mills.
Exactly how ‘green’ the following three types of green energy are is dependent on how they are created.
This type of green power uses thermal energy that has been stored just under the earth’s crust. While this resource requires drilling to access, thereby calling the environmental impact into question, it is a huge resource once tapped into. Geothermal energy has been used for bathing in hot springs for thousands of years and this same resource can be used for steam to turn turbines and generate electricity. The energy stored under the United States alone is enough to produce 10 times as much electricity as coal currently can. While some nations, such as Iceland, have easy-to-access geothermal resources, it is a resource that is reliant on location for ease of use, and to be fully ‘green’ the drilling procedures need to be closely monitored.
This renewable resource also needs to be carefully managed in order to be truly labelled as a ‘green energy’ source. Biomass power plants use wood waste, sawdust and combustible organic agricultural waste to create energy. While the burning of these materials releases greenhouse gas these emissions are still far lower than those from petroleum-based fuels.
Rather than burning biomass as mentioned above, these organic materials can be transformed into fuel such as ethanol and biodiesel. Having supplied just 2.7% of the world’s fuel for transport in 2010, the biofuels are estimated to have the capacity to meet over 25% of global transportation fuel demand by 2050.
This notebook analyzes two datasets:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'
# Disable warnings in Anaconda
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import numpy as np
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
# from __future__ import division
from __future__ import division
# Import plotly
import chart_studio
chart_studio.tools.set_credentials_file(username='', api_key='')
chart_studio.tools.set_config_file(world_readable=True, sharing='public')
import plotly.io as pio
import plotly.express as px
import chart_studio.plotly as py
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected = True)
from sklearn.linear_model import LinearRegression
df_geo = pd.read_excel('./data/green_energy.xlsx', sheet_name = 'Geo', thousands = '.', convert_float = True)
df_wre = pd.read_excel('./data/green_energy.xlsx', sheet_name = 'WREGeneration', thousands = '.', convert_float = True)
df_wre_se = pd.read_excel('./data/green_energy.xlsx', sheet_name = 'WREShareElectricity', thousands = '.', convert_float = True)
df_geo.info()
print()
df_wre.info()
print()
df_wre_se.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 231 entries, 0 to 230 Data columns (total 14 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Name 231 non-null object 1 TypeCode 231 non-null object 2 IsUNMember 231 non-null int64 3 Name2 223 non-null object 4 Name3 14 non-null object 5 Name4 4 non-null object 6 Capital 227 non-null object 7 Continent 231 non-null object 8 Region 231 non-null object 9 ISO3 231 non-null object 10 ISO2 230 non-null object 11 Latitude 231 non-null float64 12 Longitude 231 non-null float64 13 Description 3 non-null object dtypes: float64(2), int64(1), object(11) memory usage: 25.4+ KB <class 'pandas.core.frame.DataFrame'> RangeIndex: 4090 entries, 0 to 4089 Data columns (total 6 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Entity 4090 non-null object 1 Year 4090 non-null int64 2 Wind 4090 non-null float64 3 Solar 4090 non-null float64 4 GeoBiomassOther 4090 non-null float64 5 Hydro 4090 non-null float64 dtypes: float64(4), int64(1), object(1) memory usage: 191.8+ KB <class 'pandas.core.frame.DataFrame'> RangeIndex: 5395 entries, 0 to 5394 Data columns (total 3 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Entity 5395 non-null object 1 Year 5395 non-null int64 2 Value 5395 non-null float64 dtypes: float64(1), int64(1), object(1) memory usage: 126.6+ KB
df_geo.head()
df_wre.head()
df_wre_se.head()
Name | TypeCode | IsUNMember | Name2 | Name3 | Name4 | Capital | Continent | Region | ISO3 | ISO2 | Latitude | Longitude | Description | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Afghanistan | C | 1 | Afghanistan | NaN | NaN | Kabul | Asia | Southern Asia | AFG | AF | 34.5328 | 69.1658 | NaN |
1 | Albania | C | 1 | Albania | NaN | NaN | Tirana | Europe | Southern Europe | ALB | AL | 41.3300 | 19.8200 | NaN |
2 | Algeria | C | 1 | Algeria | NaN | NaN | Algiers | Africa | Northern Africa | DZA | DZ | 36.7764 | 3.0586 | NaN |
3 | American Samoa | D | 0 | American Samoa | NaN | NaN | Pago Pago | Oceania | Polynesia | ASM | AS | -14.2740 | -170.7046 | NaN |
4 | Andorra | C | 1 | Andorra | NaN | NaN | Andorra la Vella | Europe | Southern Europe | AND | AD | 42.5000 | 1.5000 | NaN |
Entity | Year | Wind | Solar | GeoBiomassOther | Hydro | |
---|---|---|---|---|---|---|
0 | Algeria | 1965 | 0.0 | 0.0 | 0.0 | 0.400 |
1 | Algeria | 1966 | 0.0 | 0.0 | 0.0 | 0.355 |
2 | Algeria | 1967 | 0.0 | 0.0 | 0.0 | 0.410 |
3 | Algeria | 1968 | 0.0 | 0.0 | 0.0 | 0.563 |
4 | Algeria | 1969 | 0.0 | 0.0 | 0.0 | 0.361 |
Entity | Year | Value | |
---|---|---|---|
0 | Afghanistan | 2000 | 66.81 |
1 | Afghanistan | 2001 | 84.12 |
2 | Afghanistan | 2002 | 80.79 |
3 | Afghanistan | 2003 | 67.09 |
4 | Afghanistan | 2004 | 63.20 |
df_geo.drop(['Name2', 'Name3', 'Name4', 'IsUNMember', 'ISO2', 'Capital', 'Description'], axis = 1, inplace = True)
df_geo.head()
Name | TypeCode | Continent | Region | ISO3 | Latitude | Longitude | |
---|---|---|---|---|---|---|---|
0 | Afghanistan | C | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
1 | Albania | C | Europe | Southern Europe | ALB | 41.3300 | 19.8200 |
2 | Algeria | C | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
3 | American Samoa | D | Oceania | Polynesia | ASM | -14.2740 | -170.7046 |
4 | Andorra | C | Europe | Southern Europe | AND | 42.5000 | 1.5000 |
TypeCode
'codes' with 'names'¶df_geo['TypeCode'].replace({'C': 'Country', 'D': 'Dependency', 'U': 'Unknown'}, inplace = True)
df_geo.head()
Name | TypeCode | Continent | Region | ISO3 | Latitude | Longitude | |
---|---|---|---|---|---|---|---|
0 | Afghanistan | Country | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
1 | Albania | Country | Europe | Southern Europe | ALB | 41.3300 | 19.8200 |
2 | Algeria | Country | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
3 | American Samoa | Dependency | Oceania | Polynesia | ASM | -14.2740 | -170.7046 |
4 | Andorra | Country | Europe | Southern Europe | AND | 42.5000 | 1.5000 |
float
columns to 2 digits¶col_names = ['Wind', 'Solar', 'Hydro', 'GeoBiomassOther']
for col_name in col_names:
df_wre[col_name] = df_wre[col_name].round(2)
df_wre.head()
Entity | Year | Wind | Solar | GeoBiomassOther | Hydro | |
---|---|---|---|---|---|---|
0 | Algeria | 1965 | 0.0 | 0.0 | 0.0 | 0.40 |
1 | Algeria | 1966 | 0.0 | 0.0 | 0.0 | 0.36 |
2 | Algeria | 1967 | 0.0 | 0.0 | 0.0 | 0.41 |
3 | Algeria | 1968 | 0.0 | 0.0 | 0.0 | 0.56 |
4 | Algeria | 1969 | 0.0 | 0.0 | 0.0 | 0.36 |
Entity
to Country
¶Since we will be only using the matching country records from the df_wre
and df_wre_se
datasets, we rename their Entity
column to Country
.
df_wre.rename(columns = {'Entity': 'Country'}, inplace = True)
df_wre_se.rename(columns = {'Entity': 'Country'}, inplace = True)
df_wre_se['Value'] = df_wre_se['Value'].round(2)
df_wre_se.head()
Country | Year | Value | |
---|---|---|---|
0 | Afghanistan | 2000 | 66.81 |
1 | Afghanistan | 2001 | 84.12 |
2 | Afghanistan | 2002 | 80.79 |
3 | Afghanistan | 2003 | 67.09 |
4 | Afghanistan | 2004 | 63.20 |
Total_WSO
and Total
columns¶df_wre['Total_WSO'] = df_wre.apply(lambda x: x['Wind'] + x['Solar'] + x['GeoBiomassOther'], axis = 1)
df_wre['Total'] = df_wre.apply(lambda x: x['Hydro'] + x['Wind'] + x['Solar'] + x['GeoBiomassOther'], axis = 1)
df_wre
Country | Year | Wind | Solar | GeoBiomassOther | Hydro | Total_WSO | Total | |
---|---|---|---|---|---|---|---|---|
0 | Algeria | 1965 | 0.00 | 0.00 | 0.00 | 0.40 | 0.00 | 0.40 |
1 | Algeria | 1966 | 0.00 | 0.00 | 0.00 | 0.36 | 0.00 | 0.36 |
2 | Algeria | 1967 | 0.00 | 0.00 | 0.00 | 0.41 | 0.00 | 0.41 |
3 | Algeria | 1968 | 0.00 | 0.00 | 0.00 | 0.56 | 0.00 | 0.56 |
4 | Algeria | 1969 | 0.00 | 0.00 | 0.00 | 0.36 | 0.00 | 0.36 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
4085 | Vietnam | 2015 | 0.18 | 0.01 | 0.07 | 57.17 | 0.26 | 57.43 |
4086 | Vietnam | 2016 | 0.21 | 0.01 | 0.07 | 66.05 | 0.29 | 66.34 |
4087 | Vietnam | 2017 | 0.27 | 0.01 | 0.08 | 88.76 | 0.36 | 89.12 |
4088 | Vietnam | 2018 | 0.31 | 0.11 | 0.08 | 84.49 | 0.50 | 84.99 |
4089 | Vietnam | 2019 | 0.49 | 4.18 | 0.08 | 65.56 | 4.75 | 70.31 |
4090 rows × 8 columns
df_wre2 = pd.merge(df_wre, df_geo[['Name', 'TypeCode', 'Continent', 'Region', 'ISO3', 'Latitude', 'Longitude']],
left_on='Country', right_on='Name')
df_wre2.drop(['Name'], axis = 1, inplace = True)
df_wre2.head()
Country | Year | Wind | Solar | GeoBiomassOther | Hydro | Total_WSO | Total | TypeCode | Continent | Region | ISO3 | Latitude | Longitude | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Algeria | 1965 | 0.0 | 0.0 | 0.0 | 0.40 | 0.0 | 0.40 | Country | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
1 | Algeria | 1966 | 0.0 | 0.0 | 0.0 | 0.36 | 0.0 | 0.36 | Country | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
2 | Algeria | 1967 | 0.0 | 0.0 | 0.0 | 0.41 | 0.0 | 0.41 | Country | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
3 | Algeria | 1968 | 0.0 | 0.0 | 0.0 | 0.56 | 0.0 | 0.56 | Country | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
4 | Algeria | 1969 | 0.0 | 0.0 | 0.0 | 0.36 | 0.0 | 0.36 | Country | Africa | Northern Africa | DZA | 36.7764 | 3.0586 |
df_wre_se2 = pd.merge(df_wre_se, df_geo[['Name', 'TypeCode', 'Continent', 'Region', 'ISO3', 'Latitude', 'Longitude']],
left_on='Country', right_on='Name')
df_wre_se2.drop(['Name'], axis = 1, inplace = True)
df_wre_se2.head()
Country | Year | Value | TypeCode | Continent | Region | ISO3 | Latitude | Longitude | |
---|---|---|---|---|---|---|---|---|---|
0 | Afghanistan | 2000 | 66.81 | Country | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
1 | Afghanistan | 2001 | 84.12 | Country | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
2 | Afghanistan | 2002 | 80.79 | Country | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
3 | Afghanistan | 2003 | 67.09 | Country | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
4 | Afghanistan | 2004 | 63.20 | Country | Asia | Southern Asia | AFG | 34.5328 | 69.1658 |
df_wre = df_wre2.copy()
df_wre_se = df_wre_se2.copy()
df_wre.to_csv('./data/wre_generation.csv', index = False)
df_wre_se.to_csv('./data/wre_share_of_electricity.csv', index = False)
Column Name | Type | UOM | Description |
---|---|---|---|
Country | string | Country name | |
Year | int | 1965-2019 | |
Wind | float | terawatt-hours (TWh) | Wind generation |
Solar | float | terawatt-hours (TWh) | Solar generation |
GeoBiomassOther | float | terawatt-hours (TWh) | Geothermal, Biomass and Other generation |
Hydro | float | terawatt-hours (TWh) | Hydro generation |
Total_WSO | float | ||
Total | float | ||
TypeCode | string | Country, Dependency, Unknown | |
Continent | string | ||
Region | string | ||
Latitude | string | ||
Longitude | string |
ge_cols_full = ['Hydro', 'Wind', 'Solar', 'GeoBiomassOther', 'Total_WSO', 'Total']
ge_cols = ['Hydro', 'Wind', 'Solar', 'GeoBiomassOther']
Year
¶df_wre_year = df_wre.groupby('Year')[ge_cols_full].sum().reset_index()
df_wre_year['Hydro %'] = round(df_wre_year['Hydro'] / df_wre_year['Total'] * 100, 1)
df_wre_year['Wind %'] = round(df_wre_year['Wind'] / df_wre_year['Total'] * 100, 1)
df_wre_year['Solar %'] = round(df_wre_year['Solar'] / df_wre_year['Total'] * 100, 1)
df_wre_year['GeoBiomassOther %'] = round(df_wre_year['GeoBiomassOther'] / df_wre_year['Total'] * 100, 1)
df_wre_year.tail()
Year | Hydro | Wind | Solar | GeoBiomassOther | Total_WSO | Total | Hydro % | Wind % | Solar % | GeoBiomassOther % | |
---|---|---|---|---|---|---|---|---|---|---|---|
50 | 2015 | 3576.21 | 823.34 | 254.34 | 519.12 | 1596.80 | 5173.01 | 69.1 | 15.9 | 4.9 | 10.0 |
51 | 2016 | 3687.44 | 954.00 | 323.63 | 527.79 | 1805.42 | 5492.86 | 67.1 | 17.4 | 5.9 | 9.6 |
52 | 2017 | 3731.78 | 1130.13 | 440.66 | 562.56 | 2133.35 | 5865.13 | 63.6 | 19.3 | 7.5 | 9.6 |
53 | 2018 | 3823.73 | 1256.28 | 574.27 | 593.38 | 2423.93 | 6247.66 | 61.2 | 20.1 | 9.2 | 9.5 |
54 | 2019 | 3883.94 | 1412.70 | 708.03 | 629.01 | 2749.74 | 6633.68 | 58.5 | 21.3 | 10.7 | 9.5 |
Continent
¶# Group dataset by Continent for 2019
df_wre_continent_2019 = df_wre[df_wre.Year == 2019].groupby('Continent')[ge_cols_full].sum().reset_index()
df_wre_continent_2019.sort_values('Total', ascending = False, inplace = True)
df_wre_continent_2019['Hydro %'] = round(df_wre_continent_2019['Hydro'] / df_wre_continent_2019['Total'] * 100, 1)
df_wre_continent_2019['Wind %'] = round(df_wre_continent_2019['Wind'] / df_wre_continent_2019['Total'] * 100, 1)
df_wre_continent_2019['Solar %'] = round(df_wre_continent_2019['Solar'] / df_wre_continent_2019['Total'] * 100, 1)
df_wre_continent_2019['GeoBiomassOther %'] = round(df_wre_continent_2019['GeoBiomassOther'] / df_wre_continent_2019['Total'] * 100, 1)
df_wre_continent_2019.head()
Continent | Hydro | Wind | Solar | GeoBiomassOther | Total_WSO | Total | Hydro % | Wind % | Solar % | GeoBiomassOther % | |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | Asia | 1819.26 | 514.94 | 395.65 | 238.95 | 1149.54 | 2968.80 | 61.3 | 17.3 | 13.3 | 8.0 |
2 | Europe | 704.03 | 438.59 | 144.33 | 207.97 | 790.89 | 1494.92 | 47.1 | 29.3 | 9.7 | 13.9 |
3 | North America | 676.93 | 354.87 | 125.11 | 96.90 | 576.88 | 1253.81 | 54.0 | 28.3 | 10.0 | 7.7 |
5 | South America | 628.28 | 68.08 | 13.72 | 72.75 | 154.55 | 782.83 | 80.3 | 8.7 | 1.8 | 9.3 |
4 | Oceania | 39.88 | 21.78 | 18.08 | 12.01 | 51.87 | 91.75 | 43.5 | 23.7 | 19.7 | 13.1 |
Country
with cumulative percentage information¶# Group dataset by Country for 2019
df_wre_country_2019 = df_wre[df_wre.Year == 2019].groupby(['Country', 'Continent'])[ge_cols_full].sum().reset_index()
df_wre_country_2019.sort_values('Total', ascending = False, inplace = True)
df_wre_country_2019['Cum. Total %'] = (df_wre_country_2019.Total.cumsum() / df_wre_country_2019.Total.sum()) * 100
df_wre_country_2019['Cum. Total_WSO %'] = (df_wre_country_2019.Total_WSO.cumsum() / df_wre_country_2019.Total_WSO.sum()) * 100
df_wre_country_2019.head(5)
Country | Continent | Hydro | Wind | Solar | GeoBiomassOther | Total_WSO | Total | Cum. Total % | Cum. Total_WSO % | |
---|---|---|---|---|---|---|---|---|---|---|
12 | China | Asia | 1269.67 | 405.70 | 223.80 | 102.83 | 732.33 | 2002.00 | 30.179327 | 26.632700 |
74 | United States | North America | 271.16 | 303.10 | 108.36 | 78.34 | 489.80 | 760.96 | 41.650487 | 44.445293 |
8 | Brazil | South America | 399.30 | 55.83 | 5.56 | 56.25 | 117.64 | 516.94 | 49.443145 | 48.723516 |
10 | Canada | North America | 381.98 | 34.17 | 4.31 | 10.81 | 49.29 | 431.27 | 55.944363 | 50.516049 |
28 | India | Asia | 161.85 | 63.31 | 46.27 | 25.35 | 134.93 | 296.78 | 60.418199 | 55.423058 |
InteractiveShell.ast_node_interactivity = 'last'
pio.templates['custom'] = go.layout.Template(
layout_colorway=['#4285F4', '#DB4437', '#F4B400', '#0F9D58',
'#185ABC', '#B31412', '#EA8600', '#137333',
'#d2e3fc', '#ceead6']
)
pio.templates.default = 'custom'
fig = go.Figure()
annotations = []
def getAnnoDict(df, ndxYear, col_name, xanchor):
ndx = df[df.Year == ndxYear].index[-1]
val = df.iloc[ndx,][col_name + ' %']
return dict(x=ndxYear, y=df.iloc[ndx,][col_name],
xanchor=xanchor, yanchor='middle', text='{}%'.format(val),
font=dict(family='Arial', size=14), showarrow=False)
for i in range(len(ge_cols)):
col_name = ge_cols[i]
_ = fig.add_trace(go.Scatter(x = df_wre_year['Year'], y = df_wre_year[ge_cols[i]], name = ge_cols[i],
marker_size = 6, marker_line_width = 0))
# labeling the left_side of the plot
if col_name in ['Hydro']:
annotations.append(getAnnoDict(df_wre_year, 1965, col_name, xanchor='right'))
annotations.append(getAnnoDict(df_wre_year, 1970, col_name, xanchor='right'))
annotations.append(getAnnoDict(df_wre_year, 1980, col_name, xanchor='right'))
if col_name in ['Hydro', 'GeoBiomassOther']:
annotations.append(getAnnoDict(df_wre_year, 1990, col_name, xanchor='right'))
annotations.append(getAnnoDict(df_wre_year, 2000, col_name, xanchor='right'))
annotations.append(getAnnoDict(df_wre_year, 2010, col_name, xanchor='right'))
annotations.append(getAnnoDict(df_wre_year, 2015, col_name, xanchor='right'))
# labeling the right side of the plot
annotations.append(getAnnoDict(df_wre_year, 2019, col_name, xanchor='left'))
_ = fig.update_xaxes(title_text = 'Year')
_ = fig.update_yaxes(title_text = 'TWh')
_ = fig.update_traces(mode = 'lines+markers')
_ = fig.update_layout(showlegend = True,
title_text = 'World green energy generation by types between 1965 and 2019',
annotations=annotations)
fig.show()
# Chart by continent and type
chart_data = []
for i in range(len(ge_cols)):
chart_data.append(go.Bar(name = ge_cols[i], x = df_wre_continent_2019['Continent'], y = df_wre_continent_2019[ge_cols[i]]))
fig = go.Figure(data = chart_data)
_ = fig.update_xaxes(title_text = 'Continents')
_ = fig.update_yaxes(title_text = ' TWh')
_ = fig.update_layout(barmode='stack',
title_text = 'World green energy generation in 2019 by continent and type')
fig.show()
# Pareto charts for each continent
continents = ['Asia', 'Europe', 'North America', 'South America']
fig = make_subplots(rows = 2, cols = 2,
specs = [[{"secondary_y": True}, {"secondary_y": True}],
[{"secondary_y": True}, {"secondary_y": True}]],
subplot_titles = continents)
for i in range(len(continents)):
rowNo = 1 if i < 2 else 2
colNo = 1 if i in [0, 2] else 2
df_tmp = df_wre_country_2019[df_wre_country_2019.Continent == continents[i]]
df_tmp['Cum. Total %'] = (df_tmp.Total.cumsum() / df_tmp.Total.sum()) * 100
df_tmp = df_tmp.nlargest(10 if continents[i] == 'Europe' else 7, columns = 'Total')
df_pareto = [80] * df_tmp.size
_ = fig.add_trace(go.Bar(x = df_tmp['Country'], y = df_tmp['Total'], name = continents[i]),
secondary_y = False, row = rowNo, col = colNo)
_ = fig.add_trace(go.Scatter(x = df_tmp['Country'], y = df_tmp['Cum. Total %'],
marker_size = 4, marker_line_width = 0, showlegend=False),
secondary_y = True, row = rowNo, col = colNo)
_ = fig.add_trace(go.Scatter(x = df_tmp['Country'], y = df_pareto,
line = dict(dash = 'dash'), hoverinfo = 'none', showlegend=False),
secondary_y = True, row = rowNo, col = colNo)
_ = fig.update_yaxes(title_text = '<b>Cum. %</b>', row = rowNo, col = colNo, secondary_y=True)
_ = fig.update_yaxes(title_text = 'TWh', row = rowNo, col = colNo)
_ = fig.update_layout(height = 1000,
title_text = 'World green energy generation in 2019 by continent and top countries')
fig.show()
df_tmp = df_wre.copy()
px.choropleth(df_tmp,
locations="ISO3",
color="Total",
hover_name="Country",
animation_frame="Year",
color_continuous_scale='RdBu',
title='World total green energy generation map between 1965 and 2019',
height=800,
width=900
)
df_tmp = df_wre_country_2019.nlargest(5, columns = 'Total')
fig = go.Figure()
for index, row in df_tmp.iterrows():
df_tmp2 = df_wre[df_wre['Country'] == row['Country']]
_ = fig.add_trace(go.Scatter(x = df_tmp2['Year'], y = df_tmp2['Total'], name = row['Country'],
marker_size = 4, marker_line_width = 0))
_ = fig.update_xaxes(title_text = 'Year')
_ = fig.update_yaxes(title_text = ' TWh')
_ = fig.update_traces(mode = 'lines+markers')
_ = fig.update_layout(showlegend = True,
title_text = 'Green energy generation between 1965 and 2019 by top 5 countries in 2019')
fig.show()
df_tmp = df_wre_country_2019.nlargest(10, columns = 'Total'). \
groupby('Country')[ge_cols + ['Total']].sum().sort_values('Total', ascending = True)
for i in df_tmp.columns:
df_tmp[i] = round(df_tmp[i] / df_tmp['Total'] * 100, 2)
df_tmp = df_tmp[ge_cols]
df_tmp = df_tmp.transpose()
df_top_10 = df_tmp.copy()
fig = go.Figure()
for index, row in df_tmp.iterrows():
fig.add_trace(go.Bar(
x=row, y=row.index,
name = index,
orientation='h'
))
fig.update_layout(barmode = 'stack',
title = 'Green energy type breakdown in top 10 countries in 2019')
fig.show()
df_final = pd.DataFrame()
for i in range(len(ge_cols)):
df_tmp = df_wre_country_2019[['Country', ge_cols[i]]]
df_tmp = df_tmp.nlargest(5, columns = ge_cols[i])
df_tmp2 = df_tmp[['Country']]
df_tmp2['Type'] = ge_cols[i]
df_tmp2['Value'] = df_tmp[ge_cols[i]]
df_final = df_final.append(df_tmp2, ignore_index=True)
df_final['No'] = df_final.index
df_final
fig = px.treemap(df_final, path=['Type', 'Country'], values='Value',
title = 'Top 5 producers of each green energy type in 2019')
fig.show()
df_wre_se_2019 = df_wre_se[(df_wre_se.Year == 2019)].sort_values('Value', ascending = False)
countries = df_top_10.transpose().reset_index()['Country'].unique()
fig = go.Figure()
for i in range(len(countries)):
df_tmp = df_wre_se[df_wre_se['Country'] == countries[i]]
_ = fig.add_trace(go.Scatter(x = df_tmp['Year'], y = df_tmp['Value'], name = countries[i],
marker_size = 6, marker_line_width = 0))
_ = fig.update_xaxes(title_text = 'Year')
_ = fig.update_yaxes(title_text = '% share of electricity production')
_ = fig.update_traces(mode = 'lines+markers')
_ = fig.update_layout(showlegend = True,
title_text = 'Share of electricity production from green sources of top 10 producers in 2019')
fig.show()