import pandas as pd
import matplotlib.pyplot as pyplot
import numpy
data = pd.read_csv('/work/ProductionConsumption-2026.csv', delimiter=" ")
#fix timestamps and process as index, pandas didn't want to convert them correctly during read
data.index = pd.to_datetime(data["Time(Local)"], format="%d.%m.%Y %H:%M:%S %z", utc=True)
data = data.drop(columns="Time(Local)")
#convert data into floats
data["Production"] = data["Production"].apply(lambda x: float(x.replace(",", ".")))
data["Consumption"] = data["Consumption"].apply(lambda x: float(x.replace(",", ".")))
data.info()
data.head()
# Plot data for single day
plottableProduction= data["Production"]['2026-03-30':'2026-03-30']
plottableConsumption = data["Consumption"]['2026-03-30':'2026-03-30']
pyplot.figure(figsize=(16,6))
pyplot.title("Electricity production and consumption in Norway during 30-03-2026")
pyplot.ylabel("MWh")
pyplot.grid(True)
pyplot.plot(plottableProduction, "r", label="Production")
pyplot.plot(plottableConsumption, "b", label="Consumption ")
#calculate times when production is more than consumption
productionGreater = numpy.greater(plottableProduction.values, plottableConsumption.values)
pyplot.fill_between(x=plottableProduction.keys(),
y1=plottableProduction.values,
y2=plottableConsumption.values,
interpolate=True,
where=productionGreater,
label="Excess power generation capacity",
)
pyplot.fill_between(x=plottableProduction.keys(),
y1=plottableProduction.values,
y2=plottableConsumption.values,
interpolate=True,
where=numpy.logical_not(productionGreater),
label="Amount of deficit in production",
)
pyplot.legend()
pyplot.show()