This notebook shows how to use utils function. In particular we show how to show to % of power production coming from renewables, in a some countries.
In [6]:
# Import Electricity Map utilities
from utils import *
# Enable inline plotting
%matplotlib inline
import matplotlib.pyplot as plt
In [7]:
# Fetch data
country_codes = ['DE', 'DK', 'FR']
df_production = get_production(country_codes, '2017-01-01', '2017-01-16', 60)
In [8]:
# Show the tail of the data frame
df_production.head()
Out[8]:
In [9]:
# Compute % of renewable production in each country
is_renewable = (df_production['mode'] == 'hydro') | (df_production['mode'] == 'wind') | (df_production['mode'] == 'solar')
df_renewable_production = df_production[is_renewable].groupby(['timestamp', 'country']).sum()
df_renewable_production['total'] = df_production.groupby(['timestamp', 'country']).sum()
df_renewable_production['ratio'] = df_renewable_production['production'] / df_renewable_production['total']
df_renewable_production.head()
Out[9]:
In [10]:
# Plot ratio of renewable
plt.figure(figsize=(10,3));
df_renewable_production.filter(['ratio']).unstack().plot(ax=plt.gca());
plt.title('Ratio of renewable (hydro, solar and wind) compared to total production');
plt.legend(country_codes);
plt.xlabel('Time');
plt.ylim([0, 1]);
In [ ]: