Created
July 20, 2019 02:46
-
-
Save kperry2215/890e7c29a5e0061124679e55f3e4000e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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