How to use the pyjstat.pyjstat.Dataset 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
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)
df = dataset.write('dataframe')
print(df)
github predicador37 / pyjstat / examples / example-2.0.py View on Github external
# -*- coding: utf-8 -*-
""" pyjstat 1.X example for JSON-stat 2.0"""

import time
from pyjstat import pyjstat

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)
github predicador37 / pyjstat / pyjstat / pyjstat.py View on Github external
them to Pandas Dataframes.

          Args:
            collection (OrderedDict): data in JSON-stat format, previously \
                                      deserialized to a python object by \
                                      json.load() or json.loads(),
            df_list (list): list variable which will contain the converted \
                            datasets.

          Returns:
            Nothing.

          """
    for item in collection['link']['item']:
        if item['class'] == 'dataset':
            df_list.append(Dataset.read(item['href']).write('dataframe'))
        elif item['class'] == 'collection':
            nested_collection = request(item['href'])
            unnest_collection(nested_collection, df_list)
github predicador37 / pyjstat / examples / example-2.0.py View on Github external
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))
github predicador37 / pyjstat / pyjstat / pyjstat.py View on Github external
warnings.warn(
        "Shouldn't use this function anymore! Now use read() methods of"
        "Dataset, Collection or Dimension.",
        DeprecationWarning
    )

    check_input(naming)
    results = []
    if type(datasets) is list:
        for idx, element in enumerate(datasets):
            for dataset in element:
                js_dict = datasets[idx][dataset]
                results.append(generate_df(js_dict, naming, value))
    elif isinstance(datasets, OrderedDict) or type(datasets) is dict or \
            isinstance(datasets, Dataset):
        if 'class' in datasets:
            if datasets['class'] == 'dataset':
                js_dict = datasets
                results.append(generate_df(js_dict, naming, value))
        else:  # 1.00 bundle type
            for dataset in datasets:
                js_dict = datasets[dataset]
                results.append(generate_df(js_dict, naming, value))
    return results
github predicador37 / pyjstat / pyjstat / pyjstat.py View on Github external
def __init__(self, *args, **kwargs):
        super(Dataset, self).__init__(*args, **kwargs)