Skip to main content

Library to handle JSON-stat data in python using pandas DataFrames.

Project description

https://travis-ci.org/predicador37/pyjstat.svg?branch=master

pyjstat is a python library for JSON-stat formatted data manipulation which allows reading and writing JSON-stat [1] format with python,using the DataFrame structures provided by the widely accepted pandas library [2]. The JSON-stat format is a simple lightweight JSON format for data dissemination. Pyjstat is inspired in rjstat [3], a library to read and write JSON-stat with R, by ajschumacher. Note that, like in the rjstat project, not all features are supported (i.e. not all metadata are converted). pyjstat is provided under the Apache License 2.0.

This library was first developed to work with Python 2.7. With some fixes (thanks to @andrekittredge), now it works with Python 3.4 too.

Installation

pyjstat requires pandas package. For installation:

pip install pyjstat

Usage

From JSON-stat to pandas DataFrame

Typical usage often looks like this:

from pyjstat import pyjstat
import requests
from collections import OrderedDict

EXAMPLE_URL = 'http://json-stat.org/samples/us-labor-ds.json'

data = requests.get(EXAMPLE_URL)
results = pyjstat.from_json_stat(data.json(object_pairs_hook=OrderedDict))
print (results)

From pandas DataFrame to JSON-stat

The same data can be converted into JSON-stat, with some unavoidable metadata loss:

from pyjstat import pyjstat
import requests
from collections import OrderedDict
import json

EXAMPLE_URL = 'http://json-stat.org/samples/us-labor-ds.json'

data = requests.get(EXAMPLE_URL)
results = pyjstat.from_json_stat(data.json(object_pairs_hook=OrderedDict))
print (results)
print (json.dumps(json.loads(pyjstat.to_json_stat(results))))

Changes

For a changes, fixes, improvements and new features reference, see CHANGES.txt.

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

pyjstat-0.3.2.tar.gz (270.0 kB view details)

Uploaded Source

File details

Details for the file pyjstat-0.3.2.tar.gz.

File metadata

  • Download URL: pyjstat-0.3.2.tar.gz
  • Upload date:
  • Size: 270.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjstat-0.3.2.tar.gz
Algorithm Hash digest
SHA256 02c63206def09f2474792981133a93459bd146eb5d6803e15daa8ee49c76c181
MD5 e9719c8838c1cb212769abd69b964c5d
BLAKE2b-256 9d0bcaf0570900d6e35ff27e075ed1f5a6a3ad36bd6d1adaee5cf0440d18a95e

See more details on using hashes here.

Supported by

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