npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dbbrowne/js-dataframe-explode

v1.0.4

Published

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

Downloads

892

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/[email protected] test
> jest

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

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

Known Issues

Please report any issues, or open a PR!

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