danfojs: powerful javascript data analysis toolkit
What is it?
danfo.js is a javascript package that provides fast, flexible, and expressive data
structures designed to make working with "relational" or "labeled" data both
easy and intuitive. It is heavily inspired by Pandas library, and provides a similar API. This means that users familiar with Pandas, can easily pick up danfo.js.
Main Features
- Easy handling of missing-data (represented as
NaN
) in floating point as well as non-floating point data - Size mutability: columns can be inserted/deleted from DataFrame
- Automatic and explicit alignment: objects can
be explicitly aligned to a set of labels, or the user can simply
ignore the labels and let
Series
, DataFrame
, etc. automatically
align the data for you in computations - Powerful, flexible groupby functionality to perform
split-apply-combine operations on data sets, for both aggregating
and transforming data
- Make it easy to convert Arrays, JSONs, List or Objects, Tensors and
differently-indexed data structures
into DataFrame objects
- Intelligent label-based slicing, fancy indexing, and querying of
large data sets
- Intuitive merging and joining data
sets
- Robust IO tools for loading data from flat-files
(CSV and delimited) and JSON data format.
- Timeseries-specific functionality: date range
generation and date and time properties.
How to install
danfo.js is hosted on NPM, and can installed via package managers like npm and yarn
npm install danfojs-node
Example usage in Nodejs
const dfd = require("danfojs-node")
dfd.read_csv("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv")
.then(df => {
df.head().print()
df.describe().print()
console.log(df.shape);
console.log(df.column_names);
df.ctypes.print()
df['Name'].print()
cols_2_remove = ['Age', 'Pclass']
df_drop = df.drop({ columns: cols_2_remove, axis: 1 })
df_drop.print()
let str_cols = df_drop.select_dtypes(["string"])
let num_cols = df_drop.select_dtypes(["int32", "float32"])
str_cols.print()
num_cols.print()
let new_vals = df['Fare'].round().values
df_drop.addColumn({ column: "fare_round", value: new_vals})
df_drop.print()
df_drop['fare_round'].print(5)
df_drop['Survived'].value_counts().print()
df_drop.tail(10).print()
df_drop.isna().sum().print()
}).catch(err => {
console.log(err);
})
To use danfo.js via script tags, copy and paste the CDN below to your HTML file
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.0.13/dist/index.min.js"></script>
Example Usage in the Browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.0.13/dist/index.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="some_div"></div>
<div id="alldiv"></div>
<script>
dfd.read_csv("https://raw.githubusercontent.com/risenW/medium_tutorial_notebooks/master/train.csv")
.then(df => {
df.describe().print()
var layout = {
title: 'A sample plot',
xaxis: {
title: 'X',
},
yaxis: {
title: 'Y',
}
};
df['Product_Weight'].plot("some_div", { kind: "histogram" })
df.plot("alldiv", { x: "Product_Price", y: "Product_Shelf_Visibility", kind: "scatter", mode: 'markers' })
}).catch(err => {
console.log(err);
})
</script>
</body>
</html>
To install Node.js version, go here
Installation from sources
To install danfo in [development mode], clone the repo:
git clone https://github.com/opensource9ja/danfojs
cd into danfojs folder and run:
npm install
Documentation
The official documentation can be found here
Discussion and Development
Most development discussions take place on github in this repo. Feel free to use the issues tab.
Contributing to Danfo
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. A detailed overview on how to contribute can be found in the contributing guide. As contributors and maintainers to this project, you are expected to abide by danfo' code of conduct. More information can be found at: Contributor Code of Conduct Javascript version of Pandas
Licence MIT