Collect GDP forecast using OCDE API with python 3.4
In [60]:
request_URL = "http://stats.oecd.org/sdmx-json/data/EO/GBR.ET_ANNPCT.A+Q/all?detail=Full&dimensionAtObservation=AllDimensions&startPeriod=2016"
# libraries to obtain the data from web
import urllib
import json
html_text = urllib.urlopen(request_URL)
html_text
Out[60]:
In [61]:
data = json.load(html_text)
data
Out[61]:
In [54]:
type(data)
Out[54]:
In [62]:
values_I_want=data['dataSets'][0]['observations']
values_I_want
Out[62]:
In [63]:
for i in values_I_want:
print(i)
In [70]:
import pandas as pd
import numpy as np
auxiliar_1= values_I_want.values()
auxiliar_2 = len(auxiliar_1)
data_values=np.empty([auxiliar_2,1])
for i in range(0,auxiliar_2):
data_values[i] = auxiliar_1[i][0]
In [71]:
data_values
Out[71]:
In [85]:
data['structure']['dimensions']['observation'][3]['values'][1]['id']
Out[85]:
In [179]:
auxiliar_1= data['structure']['dimensions']['observation'][3]['values']
auxiliar_2 = len(auxiliar_1)
index_df=[]
for i in range(0,auxiliar_2):
index_df.append(auxiliar_1[i]['id'].encode('ascii'))
index_df
Out[179]:
In [185]:
df = pd.DataFrame(data_values,index=index_df)
df.columns=['gdp_projected']
df
Out[185]:
Comentarios
Publicar un comentario