JSPM

@dbbrowne/js-dataframe-explode

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 111
  • Score
    100M100P100Q91052F
  • License ISC

JavaScript implementation of Python's Pandas#dataframe.explode method

Package Exports

  • @dbbrowne/js-dataframe-explode
  • @dbbrowne/js-dataframe-explode/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dbbrowne/js-dataframe-explode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JS-DataFrame-Explode

Javascript / Node implementation of Python's Pandas DataFrame#explode.

Test Release

Contents

Demos

const explode = require('@dbbrowne/js-dataframe-explode')

const dataFrame = {
  A: [[0, 1, 2], 'foo', [], [3, 4]],
  B: 1,
  C: [['a', 'b', 'c'], NaN, [], ['d', 'e']]
}

const singleColumnExplode = explode(dataFrame, ['A'])
console.log(singleColumnExplode)

-->>

{
  A:  [             0,               1,               2, 'foo', undefined,           3,          4],
  B:  [             1,               1,               1,     1,         1,           1,          1],
  C:  [['a', 'b', 'c'],['a', 'b', 'c'], ['a', 'b', 'c'],   NaN,         [], ['d', 'e'], ['d', 'e']],
  trackingIndex:
      [0, 0, 0,     1,    2, 3, 3],
}
const doubleColumnExplode = explode(dataFrame, ['A', 'C'])
console.log(doubleColumnExplode)

-->>

{
  A:  [  0,     1,   2, 'foo', undefined,   3,   4],
  B:  [  1,     1,   1,     1,         1,   1,   1],
  C:  ['a',   'b', 'c',   NaN, undefined, 'd', 'e'],
  trackingIndex:
      [  0,     0,   0,     1,         2,   3,   3],
}

Usage

const explode = require('@dbbrowne/js-dataframe-explode')

// your DataFrame (an object with own properties that are list-likes or primitives)
const myDataFrame = {
    A: [...]
  foo: [...]
    b: 'bar'
    1: {foo:'bar'}
  '2': 'three'
}

explode(
  myDataFrame, 
  explodeBases, // Bases to explode.  Default = Object.getOwnPropertyNames(myDataFrame)[0]
  ignoreIndex,  // By default, trackingIndex records the original index of the input list. True for trackingIndex to match the index of the exploded list. Default=false
  omitIndex     // true to omit tracking index entirely. Default=false
)
npm i @dbbrowne/js-dataframe-explode

myfile.js :

const explode = require('@dbbrowne/js-dataframe-explode')

const dataFrame = myDataFrame

var explodedDefaultColumn = explode(dataFrame)
var singleColumnExplode   = explode(dataFrame, ['C'])
var multipleColumnExplode = explode(dataFrame, ['A','C'])

Running Tests

npm run test

-->>

> @dbbrowne/js-dataframe-explode@1.0.0 test
> jest

 PASS  ./index.test.js
  js-dataframe-explode
    explodes a DataFrame-like object
      ✓ retaining the tracking index (2 ms)
      ✓ basing the tracking index on the output (1 ms)
      ✓ omitting the tracking index with "omitIndex=true"
      ✓ with primitive reference values
      ✓ based on an empty list
      inferring a tracking index if
        ✓ none is provided (1 ms)
        ✓ an empty list is provided (1 ms)
    throws on invalid inputs:
      ✓ non-matching multi-column explode elements (9 ms)
      ✓ attempting to explode a non-iterable (1 ms)
    matches pandas.DataFrame.explode docs
      ✓ single-column example (1 ms)
      ✓ multi-column example (1 ms)

Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total

Known Issues

Please report any issues, or open a PR!

  • tests to prove behaviour for dataframe prop with {1:[...], 'bar':[...], B: {foo:'bar'}}