-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflowchart_python_entsoe_day-ahead_v10.py
More file actions
40 lines (32 loc) · 1.24 KB
/
Copy pathflowchart_python_entsoe_day-ahead_v10.py
File metadata and controls
40 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import pandas as pd
import plotly.express as px
from entsoe import EntsoePandasClient
# Setup Environment
os.system('clear') # Clear console (Linux/MacOS)
# Load API Key & Configurations
API_KEY = os.getenv("ENTSOE_API_KEY")
client = EntsoePandasClient(api_key=API_KEY)
COUNTRY_CODE = "NL"
DATA_DIR = "data/"
os.makedirs(DATA_DIR, exist_ok=True)
def fetch_data(year):
file_path = os.path.join(DATA_DIR, f"prices_{year}.csv")
if os.path.exists(file_path):
return pd.read_csv(file_path, index_col=0, parse_dates=True)
start = pd.Timestamp(f"{year}-01-01", tz="UTC")
end = pd.Timestamp(f"{year}-12-31", tz="UTC")
prices = client.query_day_ahead_prices(COUNTRY_CODE, start=start, end=end)
prices.to_csv(file_path)
return prices
# Loop Through Years (2019-2024)
data_frames = [fetch_data(year) for year in range(2019, 2025)]
all_data = pd.concat(data_frames)
# Compute Annual Average Prices
annual_avg = all_data.resample("Y").mean()
# Create Histogram
fig = px.histogram(all_data, x=all_data.values.flatten(), title="Price Distribution")
fig.add_scatter(x=annual_avg.index.year, y=annual_avg.values.flatten(), mode='markers', name='Annual Average')
# Save & Display
fig.write_html("price_histogram.html")
fig.show()