Skip to main content

Library for reading JSON-stat format data.

Project description

https://travis-ci.org/26fe/jsonstat.py.svg?branch=master Documentation Status https://badge.fury.io/py/jsonstat.py.png

jsonstat.py is a library for reading the **JSON-stat** data format maintained and promoted by Xavier Badosa. The JSON-stat format is a JSON format for publishing dataset. JSON-stat is used by several institutions to publish statistical data. For example it is used by Eurostat that provide statistical information about the European Union (EU) and Istat, the Italian National Institute of Statistics)

jsonstat.py library tries to mimic as much is possible in pythonn the json-stat Javascript Toolkit One of the objectives is to be helpful in exploring dataset using ipython notebook.

For a fast overview of the feature you can start from this example notebook oecd-canada-jsonstat_v1.html

You can also check out some of the jupyter example notebook from the example directory on github or into the documentation

As bonus jsonstat.py contains an useful classes to explore dataset publiched by Istat.

You can find useful another python library pyjstat by Miguel Expósito Martín concerning json-stat format. Its main focus is to translate json-stat format into pandas dataframe.

This library is in beta status. I am actively working on it and hope to improve this project. For every comment feel free to contact me gf@26fe.com

You can find source at github , where you can open a ticket, if you wish.

You can find the generated documentation at readthedocs.

Installation

Pip will install all required dependencies. For installation:

pip install jsonstat

Usage

Simple Usage

There is a simple command line interface, so you can experiment to parse jsonstat file without write code:

# parsing collection
$ jsonstat --cache_dir /tmp http://json-stat.org/samples/oecd-canada.json
downloaded file(s) are stored into '/tmp'
download 'http://json-stat.org/samples/oecd-canada.json'
JsonstatCollection contains the following JsonStatDataSet:
0: dataset 'oecd'
1: dataset 'canada'

# parsing dataset
$ jsonstat --cache_dir /tmp  "http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/tesem120?sex=T&precision=1&age=TOTAL&s_adj=NSA"
downloaded file(s) are stored into '/tmp'
download 'http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/tesem120?sex=T&precision=1&age=TOTAL&s_adj=NSA'
name:   'Unemployment rate'
label:  'Unemployment rate'
size: 461
5 dimensions:
  0: dim id: 's_adj' label: 's_adj' size: '1' role: 'None'
  1: dim id: 'age' label: 'age' size: '1' role: 'None'
  2: dim id: 'sex' label: 'sex' size: '1' role: 'None'
  3: dim id: 'geo' label: 'geo' size: '39' role: 'None'
  4: dim id: 'time' label: 'time' size: '12' role: 'None'

code example:

url = 'http://json-stat.org/samples/oecd-canada.json'
collection = jsonstat.from_url(json_string)

# print list of dataset contained into the collection
collection.info()

# select the first dataset of the collection and print a short description
oecd = collection.dataset(0)
oecd.info()

# print description about each dimension of the dataset
for d in oecd.dimensions():
    d.info()

# print a datapoint contained into the dataset
print(oecd.value(area='IT', year='2012'))

# convert a dataset in pandas dataframe
df = oecd.to_data_frame('year')

For more python script examples see examples directory

For jupyter (ipython) notebooks see examples-notebooks directory

Support

This is an open source project, maintained in my spare time. This may well mean that particular features or functions that you would like are missing. But things don’t have to stay that way: you can contribute the project development yourself.

Bug reports and feature requests should be submitted using the github issue tracker. Please provide a full traceback of any error you see and if possible a sample file. If you are unable to make a file publicly available then contact me.

How to Contribute Code

Any help will be greatly appreciated, just follow those steps:

1. Please start a new fork for each independent feature, don’t try to fix all problems at the same time, it’s easier for those who will review and merge your changes.

  1. Write your code

3. Add unit tests for your changes! (changes without tests will not be accepted.)

4. If you added a whole new feature, or just improved something, you can be proud of it, so add yourself to the AUTHORS file :-)

  1. Update the docs!

6. When it’s done, just issue a pull request (click on the large “pull request” button on your repository) and wait for your code to be reviewed, and, if you followed all theses steps, merged into the main repository.

License

jsonstat.py is provided under the LGPL license. See LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonstat.py-0.1.8.tar.gz (23.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page