Skip to main content

A project for feeding various nested data formats into pandas

Project description

bamboo

PyPI Release Build Status

bamboo is a library for feeding nested data formats into pandas. The space of data representable in nested formats is larger than the space covered by pandas. pandas supports only data representable in a flat table (though things like multi-indexs allows certain types of tree formats to be efficiently projected into a table). Data which supports arbitrary nesting is not in general convertible to a pandas dataframe. In particular, data which contains multiple repetition structures (e.g. JSON arrays) that are not nested within each other will not be flattenable into a table.

The current data formats supported are:

  • JSON
  • Apache Avro
  • Apache Arrow
  • Profobuf (via PBD)

bamboo works by projecting a flattenable portion (a subset of the nested columns) of the data into a pandas dataframe. By projecting various combinations of columns, one can make use of all the relationships implied by the nested structure of the data.

Installation

To install from PyPI:

pip install bamboo-nested

Example

A minimal example of flattening a JSON string:

from bamboo import from_json

obj = [{'a': None, 'b': [1, 2], 'c': [5, 6]}, {'a': -1.0, 'b': [3, 4], 'c': [7, 8]}]
node = from_json(json.dumps(obj))
    > - a float64
    > - b []uint64
    > - c []uint64

Flattening just the values of column a:

df_a = node.flatten(include=['a'])
    >      a
    > 0  NaN
    > 1 -1.0

Flattening columns a and b (note that column a is repeated to match the corresponding elements of column b):

df_ab = node.flatten(include=['a', 'b'])
    >      a  b
    > 0  NaN  1
    > 1  NaN  2
    > 2 -1.0  3
    > 3 -1.0  4

Trying to flatten two repetition lists at the same level will lead to an error (as this structure is unflattenable without taking a Cartesian product):

df_bc = node.flatten(include=['b', 'c'])
    > ValueError: Attempted to flatten conflicting lists

Building

To build this project:

Building from source requires cmake (pip install cmake) and Boost.

python setup.py

Unit tests

To run the unit tests:

python setup.py test

or use nose:

nosetests python/bamboo/tests

Licensing

This project is licensed under the Apache 2.0 License. It uses the pybind11, Arrow, Avro, nlohmann JSON, and PBD projects. The licenses can be found in those projects' directories.

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

bamboo-nested-0.1.0.tar.gz (19.6 kB view hashes)

Uploaded Source

Built Distributions

bamboo_nested-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl (24.4 MB view hashes)

Uploaded CPython 3.7m

bamboo_nested-0.1.0-cp37-cp37m-macosx_10_13_intel.whl (378.8 kB view hashes)

Uploaded CPython 3.7m macOS 10.13+ intel

bamboo_nested-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl (24.4 MB view hashes)

Uploaded CPython 3.6m

bamboo_nested-0.1.0-cp36-cp36m-macosx_10_13_intel.whl (378.7 kB view hashes)

Uploaded CPython 3.6m macOS 10.13+ intel

bamboo_nested-0.1.0-cp35-cp35m-manylinux2014_x86_64.whl (24.4 MB view hashes)

Uploaded CPython 3.5m

bamboo_nested-0.1.0-cp35-cp35m-macosx_10_13_intel.whl (378.7 kB view hashes)

Uploaded CPython 3.5m macOS 10.13+ intel

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