import pandas as pd import numpy as np import import_funcs import statsmodels.api as sm # Import the BGE hourly electricity data and weather data using import_funcs.py class elec_data = import_funcs.BGEdata() weather = import_funcs.weather() # Merge into one Pandas dataframe elec_and_weather = pd.merge(weather,elec_data,left_index=True,right_index=True) elec_and_weather[:5] fig = plt.figure() plot1=elec_and_weather['tempF']['2014-02-01 00:00:00':'2014-02-07 23:00:00'].plot(color='b',label='Temp',grid=False) plot1.set_ylabel('Ambient Temp. (deg F)') legend(['Temp'],loc='upper left') plot1.set_ylim([15,65]) plot1.set_xlabel('') plot2=elec_and_weather['USAGE']['2014-02-01 00:00:00':'2014-02-07 23:00:00'].plot(color='g',secondary_y=True,label='Elec',mark_right=False,grid=False) ylabel('Elec. Usage (kWh)') legend(['Elec.'],loc='upper right') plot2.set_ylim([1,2.8]) plot2.set_xlabel('') fig.savefig('Elec_and_Temp_TS.png') fig = plt.figure() plot_scatter = plot(elec_and_weather['tempF'],elec_and_weather['USAGE'],'gx') xlabel('Outdoor Temperature (deg F)') ylabel('Hourly Electricity Use (kWh)') ylim(ymin=0) title('Hourly Electricity Consumption \n Jan. 18 through March 2014') fig.savefig('Elec_and_Temp_Scatter.png') # Linear regression on elec. vs. outdoor T (deg F) model = sm.OLS(elec_and_weather['USAGE'],sm.add_constant(elec_and_weather['tempF'])) res = model.fit() print res.summary() fig = plt.figure() plot_scatter = plot(elec_and_weather['tempF'],elec_and_weather['USAGE'],'gx') plot_model = plot(elec_and_weather['tempF'],res.fittedvalues,'b',label='OLS $R^2$=%.2f' % res.rsquared) xlabel('Outdoor Temperature (deg F)') ylabel('Hourly Electricity Use (kWh)') ylim(ymin=0) title('Hourly Electricity Consumption \n Jan. 18 through March 2014') legend() fig.savefig('Elec_And_Temp_OLS.png') fig = plt.figure() plot1=elec_and_weather['wspdm']['2014-02-01 00:00:00':'2014-02-07 23:00:00'].plot(color='b',label='Wind',grid=False) plot1.set_ylabel('Mean Wind Speed (kph)') legend(loc='upper left') #plot1.set_ylim([15,65]) plot1.set_xlabel('') plot2=elec_and_weather['USAGE']['2014-02-01 00:00:00':'2014-02-07 23:00:00'].plot(color='g',secondary_y=True,label='Elec',mark_right=False,grid=False) ylabel('Elec. Usage (kWh)') legend(['Elec.'],loc='upper right') plot2.set_ylim([1,2.8]) plot2.set_xlabel('') #fig.savefig('Elec_and_Temp_TS.png') fig = plt.figure() plot_scatter = plot(elec_and_weather['wspdm'],elec_and_weather['USAGE'],'gx') xlabel('Wind Speed (km/h)') ylabel('Elec. Usage (kWh)') #ylim(ymin=0) #title('Hourly Electricity Consumption \n Jan. 18 through March 2014') #fig.savefig('Elec_and_Temp_Scatter.png') elec_and_weather['wspdm'].hist() fig = plt.figure() plot1=elec_and_weather['hum']['2014-02-01 00:00:00':'2014-02-07 23:00:00'].plot(color='b',label='Hum.',grid=False) plot1.set_ylabel('Relative Humidity (%)') legend(loc='lower right') #plot1.set_ylim([15,65]) plot1.set_xlabel('') plot2=elec_and_weather['USAGE']['2014-02-01 00:00:00':'2014-02-07 23:00:00'].plot(color='g',secondary_y=True,label='Elec',mark_right=False,grid=False) ylabel('Elec. Usage (kWh)') legend(['Elec.'],loc='upper right') plot2.set_ylim([1,2.8]) plot2.set_xlabel('') #fig.savefig('Elec_and_Temp_TS.png') fig = plt.figure() plot_scatter = plot(elec_and_weather['hum'],elec_and_weather['USAGE'],'gx') xlabel('Relative Humidity (%)') ylabel('Elec. Usage (kWh)') #ylim(ymin=0) #title('Hourly Electricity Consumption \n Jan. 18 through March 2014') #fig.savefig('Elec_and_Temp_Scatter.png') elec_and_weather['hum'].hist()