# convert date and time info to datetime object def cleanUpDateTime(df): # creates a function to convert from string to datetime info # still need to add info to keep time zone info df['DateTime'] = "" for n in range(df.shape[0]): y = df.Date[n].replace("T", "") z = y.replace("Z", "") df['DateTime'][n] = datetime.strptime(z, '%Y%m') return (df) ng_tx = cleanUpDateTime(ng_tx) elec_tx = cleanUpDateTime(elec_tx) # set the datetime info to be the index ng_tx = ng_tx.set_index(['DateTime']) elec_tx = elec_tx.set_index(['DateTime']) # save csv files of monthly natural gas and electricity prices ng_tx.to_csv('CSV_Files/MonthlyNatGasPrices.csv') elec_tx.to_csv('CSV_Files/MonthlyElectricityPrices.csv') print('convertedIndex', ng_tx.head(5)) # make a figure def plotGasAndElecPrices(priceData, figName): plt.figure(figsize=(5, 3)) # add a matplotlib converter to get rid of this error fig, ax = plt.subplots()
# find min and max demands max_tex = max(tx.demand) print('Maximum demand, Texas:', max_tex) min_tex = min(tx.demand) print('Minimum demand, Texas:', min_tex) max_tex_south = max(tx_s.demand) print('Maximum demand, South Central Texas:', max_tex_south) min_tex_south = min(tx_s.demand) print('Minimum demand, South Central Texas:', min_tex_south) # find scale factor between South Central Texas and Texas ratio = max_tex_south / max_tex print('Max ERCOT South Central/Max ALL Texas:', ratio) # set the DateTime to be the index tx = tx.set_index(['DateTime']) tx_s = tx_s.set_index(['DateTime']) # slice 2018 from ALL-Texas demand, save it to csv file txSlice = tx['2019-01-01 00:00:00':'2018-01-01 00:00:00'] tx2018 = txSlice.iloc[::-1] tx2018.to_csv('CSV_Files/HourlyTxDemand2018.csv') # create a notional 2018 hourly electrical demand for ERCOT SCEN based on ratio of peaks tx_SCEN = tx2018.copy() tx_SCEN["demand"] *= ratio tx_SCEN.to_csv('CSV_Files/HourlyTxScenDemand2018-Notional.csv') print(tx_SCEN.head()) tx_SCEN = cleanUpDateTime(tx_SCEN) print(tx_SCEN.head())