Daily Duration Curve#
Goal
Display a duration curve (sum frequency) of daily electricity consumption. The curve ranks daily totals from highest to lowest, revealing how many days exceed a given consumption level.
Data Basis
The dataset flatElectricity.csv contains cumulative electricity meter readings at 15-minute intervals (columns: time, FlatA_Ele, FlatB_Ele, FlatC_Ele, FlatD_Ele; separator ;). We use FlatA_Ele, compute consumption via diff(), and sum it per day, keeping only days without missing readings.
Data Preparation#
import pandas as pd
url = "https://raw.githubusercontent.com/retomarek/edap/main/edap/sampleData/flatElectricity.csv"
raw = pd.read_csv(url, sep=";")
# Parse timestamp and set as index
raw["time"] = pd.to_datetime(raw["time"])
raw = raw.set_index("time")
# Consumption per 15 minutes from the cumulative meter readings (kWh)
consumption = raw["FlatA_Ele"].diff()
# Daily sums of complete days only (all 96 quarter-hours have a reading):
# without min_count, days with missing data would show up as low or zero
# consumption
daily = consumption.resample("D").sum(min_count=96).dropna()
# Build clean 2-column DataFrame [timestamp, value]
df = daily.reset_index()
df.columns = ["timestamp", "value"]
df.head()
| timestamp | value | |
|---|---|---|
| 0 | 2018-12-01 | 14.324 |
| 1 | 2018-12-02 | 14.141 |
| 2 | 2018-12-03 | 12.444 |
| 3 | 2018-12-04 | 7.954 |
| 4 | 2018-12-05 | 5.732 |
Visualization#
from pyedautils.plots import plot_sum_frequency
fig = plot_sum_frequency(df, resolution="daily", reverse=True,
title="Electricity — Daily Duration Curve",
ylab="Electricity [kWh/d]")
fig.show()
Customization
reverse=True puts the highest value first (classic duration curve); without it the values are sorted from lowest to highest. resolution is "daily" or "hourly", and year=2019 restricts the curve to one year.
fig = plot_sum_frequency(df, resolution="daily", reverse=True, year=2019, ylab="Electricity [kWh/d]")