Giter Site home page Giter Site logo

zebras's Introduction

zebras - data analysis library for javascript

Coverage Status

Zebras is a data manipulation and analysis library written in JavaScript offering the convenience of pandas or R.

Zebras is especially useful for JS data analysis and visualization projects in notebooks on ObservableHQ or using the JS Jupyter kernel.

Unlike pandas, zebras is purely functional. All zebras functions accept data as an argument and return a new data structure transformed, and 'dataframes' are simply arrays of JS objects without any special methods.

Zebras is built on top of Ramda. Think of zebras as a collection of Ramda functions, and compositions of them, curated and repackaged for common data processing and data analysis tasks.

As in Ramda, all zebras functions are curried, making them easier to chain together. This means that, for example, zebras.sortByCol(col, df) is equivalent to zebras.sortByCol(col)(df).

An interactive introduction to the zebras library - using S&P 500 data - is available as an Observable notebook.

See the project roadmap on the zebras wiki here.

A guide to using zebras in a JS Jupyter notebook can be found on the zebras wiki here.

To Install

Locally with Node / Jupyter

npm install zebras --save
const z = require("zebras")

Online in an Observable notebook

z = require("zebras")

Example Usage

const z = require("zebras")
const data = z.readCSV("data.csv")
const parsedData = z.parseNums(["speed", "acc"], data)
const speed = z.getCol("speed", parsedData)
const avgSpeed = z.mean(speed)

Note: make sure numerical data imported into Zebras does not contain commas ("2342.5", not "2,342.5") - commas within numbers will throw off the parsing and lead to unexpected results.

Piping example:

const z = require("zebras")
const avgSpeed = z.pipe([
  // array of functions for input to travel through
  z.readCSV,
  z.parseNums(["speed", "acc"]),
  z.getCol("speed"),
  z.mean,
])("data.csv")

Documentation

See the full documentation here.

zebras's People

Contributors

a1ip avatar amytych avatar dependabot[bot] avatar lennardv2 avatar marcosfede avatar nickginsberg avatar nickslevine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zebras's Issues

Implement merge

Implement function to join dataframes on columns. See pandas implementation here.

Convert to AMD module

Convert zebras.js to an AMD module so z = require('zebras') will work on Observable rather than having to do z = require('https://bundle.run/zebras).

Make zebras browser friendly

Right now Zebras is intended for use either in Jupyter notebook or in ObservableHQ. But there might be a value in allowing it to be used in the browser as well. To be able to use some of its methods inside web applications, etc.

It seems that it wouldn't be too difficult to make it happen, the main blocker right now seems to be that everything is in one file and it uses the file system:

const fs = require("fs")

An idea could be to modularise it exposing methods as individual exports. This also has the perk of improved maintainability going forward instead of cramming more functionality into one file. Similarly to how Ramda is structured.

It'd be also advised, maybe as next step and not right away, to introduce a build step to produce different kinds of dist bundles (es6, cjs, umd).

Question about `head` and `tail`

It's not super straightforward that these methods print something as a string. Wouldn't it be more useful and clear to have them return a subset of df (similarly to filter)?

Then printing of head or tail could be done via Z.print(Z.head(10, df)) which is more clear on the intent? Or it could also be encapsulated in print-specific helpers: printHead and printTail.

Side note, there is console.log() lingering in tail:

console.log(print(truncated))

Does not import data with a comma in them

Excel surrounds these with cases with quotations when it is in a CSV. Zebras seems to just ignore these rows of data. This could be a user error. Please comment if you know a fix.

Implement map for groupby objects

It would be cool to have a way to map groupby objects. It could preserve the same keys and map the values, just like ramda's map, or just get the values to get a dataframe-like result, roughly like:

function apply(fn, df){
  return R.pipe(
    R.mapObjIndexed((value, index) => fn(value, index)),
    R.values
  )(df)
}

Sort df by multiple columns

Change z.sortByCol(columnName, direction, df) so that it accepts an array of column names and sorts a df by the specified columns, giving precedence to columns listed earlier, as in pandas.

Proposal: Move TODO.md to issues on GitHub

First off, I love this tool, would love to contribute!

Personally, I like to work with GitHub issues rather than a TODO.md file, since it's easier to reference in PR's/comments. Contributors could also comment on the issue if they want to work on it, which is a little harder to do in a committed file. Also, tagging issues with feature or bug can be pretty helpful!

gbCount, gbMean etc. not curried

Hi,

It seems that you can't do a pipe like this:

const data = [{"Day": "Monday", "value": 10}, {"Day": "Tuesday", "value": 5}, {"Day": "Monday", "value": 7}]

Z.pipe([
  Z.groupBy(s => s.Day),
  Z.gbSum('value') // Uncaught TypeError: g.call is not a function
])(data)

It's because the gbSum function (and the other gb funcs) is not curried?

Add tests

I think it would be great to have tests. It would be a good next step, before further planned refactoring, to have a piece of mind that nothing gets broken in the process.

If you didn't already, I could add a testing setup with mocha and start adding tests until we get full coverage.

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.