Analysis of Electricity Exchange

This notebook shows how to use utils function. In particular we show how to pull data of electricity exchange.

We first import utils function. This lets you access a set of handy functions :


In [1]:
from utils import *

# Enable inline plotting
%matplotlib inline 
from ggplot import *

We then pull exchange data for France, between Nov. 2016 and Jan. 2017. To achieve this, we use the function get_exchange :


In [2]:
df_exchange = get_exchange(['FR'],'2016-11-01','2017-01-10', 1440)


Fetching country FR..

Let's take a first look at the dataframe returned. In the example below, the first row means that France exported on Nov. 1st, 6260 MW to Germany.


In [3]:
df_exchange.head()


Out[3]:
country_from country_to net_flow timestamp
0 FR DE -6260 2016-11-01 00:00:00+00:00
1 FR GB 1198 2016-11-01 00:00:00+00:00
2 FR ES 2850 2016-11-01 00:00:00+00:00
3 FR IT -613 2016-11-01 00:00:00+00:00
0 FR DE -4618 2016-11-02 00:00:00+00:00

Let's run a quick analysis : on the above period, to which country France has exported the most ? From which country it has imported the most ?

Looking at the table below, it looks like France has imported the most power from Belgium (71 154 MW), and has exported the most power to Spain (100 527 MW).


In [4]:
df_exchange.groupby('country_to').sum().sort_values('net_flow',ascending=False)


Out[4]:
net_flow
country_to
BE 71154
GB 31699
CH 5445
IT -5891
DE -21468
ES -100527

How does this evolve in time ? In the graph below, we show how electricity exchanges have evolved from November to January. We notice for instance that import and export vary with a given country.

For instance, France exported a lot of electricity to Germany during November, but started importing more in December :


In [5]:
df_exchange['timestamp'] = df_exchange['timestamp'].apply(lambda x: arrow.get(x).datetime)

In [6]:
ggplot(aes(x='timestamp',y='net_flow', colour='country_to'),data=df_exchange) +\
    geom_line() +\
    ggtitle('Evolution of French Electricity Exchange (Nov 2016, Jan 2017)') +\
    xlab('Date') +\
    scale_x_date(labels = date_format("%b")) +\
    facet_wrap('country_to') +\
    theme_bw()


/usr/local/lib/python2.7/site-packages/ggplot/ggplot.py:192: RuntimeWarning: Setting "mpl.rcParams['axes.prop_cycle']=cycler(u'color', [u'#333333', u'#348ABD', u'#7A68A6', u'#A60628', u'#467821', u'#CF4457', u'#188487', u'#E24A33'])" raised an Exception: u'axes.prop_cycle is not a valid rc parameter.See rcParams.keys() for a list of valid parameters.'
  warnings.warn(msg, RuntimeWarning)
Out[6]:
<ggplot: (279363009)>