Skip to content

Instantly share code, notes, and snippets.

@kperry2215
Created July 20, 2019 02:44
Show Gist options
  • Save kperry2215/f8add9c160998a7c086e3ab94434795a to your computer and use it in GitHub Desktop.
Save kperry2215/f8add9c160998a7c086e3ab94434795a to your computer and use it in GitHub Desktop.
#Pull in natural gas time series data
series_ID='NG.N3035TX3.M'
nat_gas_df=retrieve_time_series(api, series_ID)
nat_gas_df.reset_index(level=0, inplace=True)
#Rename the columns
nat_gas_df.rename(columns={'index':'Date',
nat_gas_df.columns[1]:'Nat_Gas_Price_MCF'},
inplace=True)
#Convert the Date column into a date object
nat_gas_df['Date']=pd.to_datetime(nat_gas_df['Date'])
#Set Date as a Pandas DatetimeIndex
nat_gas_df.index=pd.DatetimeIndex(nat_gas_df['Date'])
#Decompose the time series into parts
decompose_time_series(nat_gas_df['Nat_Gas_Price_MCF'])
#Merge the two time series together based on Date Index
master_df=pd.merge(electricity_df['Electricity_Price'], nat_gas_df['Nat_Gas_Price_MCF'],
left_index=True, right_index=True)
master_df.reset_index(level=0, inplace=True)
#Plot the two variables in the same plot
plt.plot(master_df['Date'],
master_df['Electricity_Price'], label="Electricity_Price")
plt.plot(master_df['Date'],
master_df['Nat_Gas_Price_MCF'], label="Nat_Gas_Price")
# Place a legend to the right of this smaller subplot.
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.title('Natural Gas Price vs. TX Electricity Price over Time')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment