Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'")
EXAMPLE_URL = 'http://www.cso.ie/StatbankServices/StatbankServices.svc/' \
'jsonservice/responseinstance/TSM01'
# Elapsed time for pyjstat operations only (without network latency)
start = time.time()
# read dataset from url
dataset_from_json_url = pyjstat.Dataset.read(EXAMPLE_URL)
# write dataframe
dataframe = dataset_from_json_url.write('dataframe')
print(dataframe)
# read dataset from dataframe
dataset_from_dataframe = pyjstat.Dataset.read(dataframe)
print(dataset_from_dataframe)
# write dataset to json-stat string
json_string = dataset_from_dataframe.write()
print(json_string)
# read dataset from json-stat string
dataset_from_json_string = pyjstat.Dataset.read(json_string)
print(dataset_from_json_string)
end = time.time()
print("Time: " + str(end - start))