read electricity data locally
This commit is contained in:
parent
c4ec4590c2
commit
32e8e59c82
22
read_data.py
22
read_data.py
@ -4,6 +4,7 @@ import csv
|
||||
|
||||
sunlight_file_name = 'lightintensity.xlsx'
|
||||
factory_demand_file_name = 'factory_power1.xlsx'
|
||||
electricity_price_data = 'electricity_price_data.csv'
|
||||
|
||||
df_sunlight = pd.read_excel(sunlight_file_name, header=None, names=['SunlightIntensity'])
|
||||
|
||||
@ -25,20 +26,31 @@ print(df_power.head())
|
||||
|
||||
df_combined = df_sunlight_resampled.join(df_power)
|
||||
|
||||
|
||||
df_combined.to_csv('combined_data.csv', index=True, index_label='Time')
|
||||
|
||||
price_data = np.random.uniform(0.3, 0.3, len(times))
|
||||
def read_csv(file_path):
|
||||
return pd.read_csv(file_path, index_col='Time', usecols=['Time', 'ElectricityPrice'])
|
||||
|
||||
# price_data = np.random.uniform(0.3, 0.3, len(times))
|
||||
|
||||
# 创建DataFrame
|
||||
price_df = pd.DataFrame(data={'Time': times, 'ElectricityPrice': price_data})
|
||||
price_df = read_csv(electricity_price_data)
|
||||
price_df.index = pd.to_datetime(price_df.index)
|
||||
price_df = price_df.reindex(df_combined.index)
|
||||
|
||||
price_df.set_index('Time', inplace=True)
|
||||
# price_df.set_index('Time', inplace=True)
|
||||
|
||||
# 保存到CSV文件
|
||||
price_df.to_csv('electricity_price_data.csv', index=True)
|
||||
print(price_df.head())
|
||||
# price_df.to_csv('electricity_price_data.csv', index=True)
|
||||
print("price____")
|
||||
print(price_df.index)
|
||||
print("df_combined____")
|
||||
print(df_combined.index)
|
||||
|
||||
print("Electricity price data generated and saved.")
|
||||
|
||||
|
||||
df_combined2 = df_combined.join(price_df)
|
||||
print(df_combined2.head())
|
||||
# 保存结果
|
||||
|
Loading…
Reference in New Issue
Block a user