Accessing the energy_analysis_toolbox from the Pandas API#

You can access the capacities of eat directly from a pandas object by adding the following import:

[1]:
import energy_analysis_toolbox.pandas

On a Series#

Considering any timeseries, the computation toolbox can be used for any useful processing.

[2]:
import pandas as pd
import numpy as np
n_elements = 100
power_series = pd.Series(
    data = 5*np.sin(np.linspace(0, 6, n_elements)) + np.random.randn(n_elements),
    index = pd.date_range(
        start = '2019-01-01',
        periods = n_elements,
        freq = '5min',
    )
)
ax = power_series.plot()
ax.set_ylabel('Power (W)')
ax.set_xlabel('Time');
../_images/user_guide_using_the_accessor_3_0.png

Transforming the power to energy#

[3]:
ax =power_series.eat.to_energy().plot()
ax.set_ylabel('Energy (J)')
ax.set_xlabel('Time');
../_images/user_guide_using_the_accessor_5_0.png

Resampling to a fixed frequency#

For power and energy, a specific accessor using the right interpolation method exists.

[4]:
ax = power_series.eat.power_to_freq(freq='30min').plot(drawstyle='steps-post')
power_series.plot(
    ax=ax,
    drawstyle='steps-post',
)
ax.set_ylabel('Power (W)')
ax.set_xlabel('Time')
ax.legend(['resampled 30min', 'raw']);
../_images/user_guide_using_the_accessor_8_0.png

A more generic timeseries resampling is also available which let you choose the method :

[5]:
ax = power_series.eat.power_to_freq(freq='30min').plot(
    drawstyle='steps-post',
    label='resampled 30min',
    legend=True,
)
power_series.eat.to_freq(
    freq='30min',
    method='flow_rate_conservative',
).plot(
    drawstyle='steps-post',
    label='resampled 30min (custom)',
    legend=True,
    ax=ax,
)
power_series.plot(
    ax=ax,
    drawstyle='steps-post',
    legend='True',
    label='original',
)
ax.set_ylabel('Power (W)')
ax.set_xlabel('Time');
../_images/user_guide_using_the_accessor_10_0.png

Detective interval with power over a threshold#

[6]:
threshold=2
oversonsumptions = power_series.eat.intervals_over(threshold)

ax = power_series.plot()
ax.axhline(threshold, color='red')
for idx, (start, end) in oversonsumptions.iterrows():
    ax.axvspan(start, end, color='red', alpha=0.5)

ax.set_ylabel('Power (W)')
ax.set_xlabel('Time');
../_images/user_guide_using_the_accessor_12_0.png

Filling data holes#

A missing entry is cumbersome for a Series, as there is no “duration” associated with a value.

You can use et to fill the data holes. The Example bellow shows how to fill the data hole to 0.

[7]:
missing_data_series = power_series.drop( power_series.index[10:20] )
ax = missing_data_series.plot(marker='o', linestyle='none')

filled_series = missing_data_series.eat.fill_data_holes(fill_value=0)
ax = filled_series.plot(ax=ax, marker=".", linestyle='none')
ax.set_ylabel('Power (W)')
ax.set_xlabel('Time')
ax.legend(['missing entries', 'filled to Zero']);
../_images/user_guide_using_the_accessor_14_0.png