#exportsdefget_ets_mkt_data():# Constructing endpointapi_root='https://www.quandl.com/api/v3/datasets'quandl_code='CHRIS/ICE_C1'endpoint_url=f'{api_root}/{quandl_code}.json'# Making the data requestparams={'api_key':api_key}r=requests.get(endpoint_url,params=params)# Converting to a dataframedataset=r.json()['dataset']df=pd.DataFrame(dataset['data'],columns=dataset['column_names'])# Cleaning the dataframedf.columns=df.columns.str.lower().str.replace('.','').str.replace(' ','_')df=df.rename(columns={'date':'datetime'}).set_index('datetime')df['close']=df['open']+df['change']df.index=pd.to_datetime(df.index)df=df.sort_index()returndf
%%timedf_ets=get_ets_mkt_data()df_ets.head()
Wall time: 1.4 s
C:\Users\Ayrto\anaconda3\envs\ETSWatch\lib\site-packages\ipykernel_launcher.py:17: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.
fig,ax=plt.subplots(dpi=150)df_ets['volume'].groupby(df_ets.index.dayofyear).mean().plot()hlp.hide_spines(ax)ax.set_xlim(0,365)ax.set_ylim(0)ax.set_xlabel('Day of the Year')ax.set_ylabel('Average Daily Volume (tonne CO2)')