Generate Pandas data frames, load and extract data, based on JSON Table Schema descriptors.
Project description
Generate and load Pandas data frames based on JSON Table Schema descriptors.
Installation
$ pip install datapackage $ pip install jsontableschema-pandas
Quick start
You can easily load resources from a data package as Pandas data frames by simply using datapackage.push_datapackage function:
>>> import datapackage
>>> data_url = 'http://data.okfn.org/data/core/country-list/datapackage.json'
>>> storage = datapackage.push_datapackage(data_url, 'pandas')
>>> storage.tables
['data___data']
>>> type(storage['data___data'])
<class 'pandas.core.frame.DataFrame'>
>>> storage['data___data'].head()
Name Code
0 Afghanistan AF
1 Åland Islands AX
2 Albania AL
3 Algeria DZ
4 American Samoa AS
Also it is possible to pull your existing data frame into a data package:
>>> datapackage.pull_datapackage('/tmp/datapackage.json', 'country_list', 'pandas', tables={
... 'data': storage['data___data'],
... })
Storage
Tabular Storage
Package implements Tabular Storage interface.
We can get storage this way:
>>> from jsontableschema_pandas import Storage
>>> storage = Storage()
Storage works as a container for Pandas data frames. You can define new data frame inside storage using storage.create method:
>>> storage.create('data', {
... 'primaryKey': 'id',
... 'fields': [
... {'name': 'id', 'type': 'integer'},
... {'name': 'comment', 'type': 'string'},
... ]
... })
>>> storage.tables
['data']
>>> storage['data'].shape
(0, 0)
Use storage.write to populate data frame with data:
>>> storage.write('data', [(1, 'a'), (2, 'b')])
>>> storage['data']
id comment
1 a
2 b
Also you can use tabulator to populate data frame from external data file:
>>> import tabulator
>>> with tabulator.topen('data/comments.csv', with_headers=True) as data:
... storage.write('data', data)
>>> storage['data']
id comment
1 a
2 b
1 good
As you see, subsequent writes simply appends new data on top of existing ones.
Contributing
Please read the contribution guideline:
Thanks!
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
Built Distribution
File details
Details for the file jsontableschema-pandas-0.1.4.tar.gz
.
File metadata
- Download URL: jsontableschema-pandas-0.1.4.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c5ecf2d3e3fc8afbd9521f17352bd587d362919a51130533425c4c2dc323501 |
|
MD5 | 982f1d7d1035f09f5dc766df97230042 |
|
BLAKE2b-256 | 9f48846bd04d4dbf3ccbfad8f225167a83a4a988350a55362ee204ec34dee86a |
Provenance
File details
Details for the file jsontableschema_pandas-0.1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: jsontableschema_pandas-0.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e789f4a12e257e9cd868e8a9da6009ca18f56e580f5f50a9bd62422774b97e01 |
|
MD5 | b6124686e378a70ca7646d8d673dd619 |
|
BLAKE2b-256 | aa3ec68aa039a9dce5b2a6dbc36f236c6b9d14445199a2d2a0e5acb7773a1fb0 |