Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# print(df)
#
# dataset_from_df = pyjstat.Dataset.read(df)
# print(dataset_from_df.write())
#
# EXAMPLE_URL = 'http://json-stat.org/samples/oecd.json'
# query = [{'concept': 'UNR'}, {'area': 'US'}, {'year': '2010'}]
#
# dataset = pyjstat.Dataset.read(EXAMPLE_URL)
# print(dataset.get_value(query))
from pyjstat import pyjstat
EXAMPLE_URL = 'http://json-stat.org/samples/collection.json'
collection = pyjstat.Collection.read(EXAMPLE_URL)
df_list = collection.write('dataframe_list')
print(df_list)
#
# EXAMPLE_URL = 'http://json-stat.org/samples/hierarchy.json'
#
# dataset = pyjstat.Dataset.read(EXAMPLE_URL)
# df = dataset.write('dataframe')
# print(df)
EXAMPLE_URL = 'http://web.ons.gov.uk/ons/api/data/dataset/DC1104EW.json?'\
'context=Census&jsontype=json-stat&apikey=DCOpn8BU2i&'\
'geog=2011HTWARDH&diff=&totals=false&'\
'dm/2011HTWARDH=E12000007'
dataset = pyjstat.Dataset.read(EXAMPLE_URL)
def get(self, element):
"""Gets ith element of a collection in an object of the corresponding \
class.
Args:
output(string): can accept 'jsonstat' or 'dataframe_list'
Returns:
Serialized JSONstat or a list of Pandas Dataframes,depending on \
the 'output' parameter.
"""
if self['link']['item'][element]['class'] == 'dataset':
return Dataset.read(self['link']['item'][element]['href'])
elif self['link']['item'][element]['class'] == 'collection':
return Collection.read(self['link']['item'][element]['href'])
elif self['link']['item'][element]['class'] == 'dimension':
return Dimension.read(self['link']['item'][element]['href'])
else:
raise ValueError(
"Class not allowed. Please use dataset, collection or "
"dimension'")