Help: Conversion of Electricity Data into Time Series Data - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Help: Conversion of Electricity Data into Time Series Data (/thread-40605.html) |
Help: Conversion of Electricity Data into Time Series Data - SmallGuy - Aug-25-2023 I want to plot a power load curve with the electricity consumption data. I download a load profile from a EV charger. The data file is a excel containing the energy start time, stop time, energy consumption and duration data. I have converted the energy data to the load. [attachment=2505] Now i am stuck how to convert the data into a per-minute time series data similar to the following. Does anyone know how to do the conversion? [attachment=2506] RE: Help: Conversion of Electricity Data into Time Series Data - deanhystad - Sep-14-2023 Something like this? import pandas as pd from datetime import datetime, timedelta # Read power report spreadsheet power_report = pd.read_excel("test.xlsx") # Get starting time. Here I round down first time in report to the minute. t = pd.Timestamp(power_report["Energy start time"].values[0]).replace(second=0) # Get power for each interval interval = timedelta(minutes=1) power_usage = [] for start, stop, power in zip( power_report["Energy start time"].values, power_report["Energy stop time"].values, power_report["Power (kW)"].values): while t < start: power_usage.append({"Time": t, "Load kW": 0.00}) t += interval while t < stop: power_usage.append({"Time": t, "Load kW": power}) t += interval power_usage = pd.DataFrame(power_usage) print(power_usage)Post text, not screenshots. I wrote a little script to make some fake power data and stuff it in a spreadsheet. If you had posted text instead of a screenshot, I could cut/paste and use your data. Make it easy to answer your question and you will get faster and better answers. RE: Help: Conversion of Electricity Data into Time Series Data - jeffreyteague - Oct-04-2023 import pandas as pd import matplotlib.pyplot as plt # Load your Excel file into a pandas DataFrame # Assuming your Excel file has columns like 'Start Time', 'Stop Time', 'Energy Consumption', 'Duration' df = pd.read_excel('your_file.xlsx') # Convert duration to hours (assuming it's in minutes) df['Duration (hours)'] = df['Duration'] / 60 # Calculate power load (energy consumption divided by duration) df['Power Load (kW)'] = df['Energy Consumption'] / df['Duration (hours)'] # Plot the power load curve plt.figure(figsize=(10, 6)) plt.plot(df['Start Time'], df['Power Load (kW)'], marker='o', linestyle='-') plt.title('Power Load Curve') plt.xlabel('Time') plt.ylabel('Power Load (kW)') plt.xticks(rotation=45) plt.grid(True) plt.tight_layout() plt.show() RE: Help: Conversion of Electricity Data into Time Series Data - deanhystad - Oct-04-2023 The spreadsheet from the original post has an energy start time and and energy stop time. There are gaps betwen the stop time and the next start time. A power usage graph should look like a series of steps, with the power usage as a horizontal line between the start and stop times, and zero between the stop time and the next start time. Granted, a plot of the target format would not be steps either, but would be a closer representation of the data than a line chart showing the power usage at only the start times. |