Skip to content

Instantly share code, notes, and snippets.

@kperry2215
Created July 20, 2019 02:42
Show Gist options
  • Save kperry2215/578dfb246268d66ce31c7844531d075b to your computer and use it in GitHub Desktop.
Save kperry2215/578dfb246268d66ce31c7844531d075b to your computer and use it in GitHub Desktop.
def retrieve_time_series(api, series_ID):
"""
Return the time series dataframe, based on API and unique Series ID
api: API that we're connected to
series_ID: string. Name of the series that we want to pull from the EIA API
"""
#Retrieve Data By Series ID
series_search = api.data_by_series(series=series_ID)
##Create a pandas dataframe from the retrieved time series
df = pd.DataFrame(series_search)
return df
###Execute in the main block
#Create EIA API using your specific API key
api_key = "YOR API KEY HERE"
api = eia.API(api_key)
#Pull the electricity price data
series_ID='ELEC.PRICE.TX-ALL.M'
electricity_df=retrieve_time_series(api, series_ID)
electricity_df.reset_index(level=0, inplace=True)
#Rename the columns for easer analysis
electricity_df.rename(columns={'index':'Date',
electricity_df.columns[1]:'Electricity_Price'},
inplace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment