How to use the pyjstat.pyjstat.Collection.read function in pyjstat

To help you get started, we’ve selected a few pyjstat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github predicador37 / pyjstat / examples / examples.py View on Github external
# 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)
github predicador37 / pyjstat / pyjstat / pyjstat.py View on Github external
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'")