MCPcopy Index your code
hub / github.com/javascriptdata/danfojs

github.com/javascriptdata/danfojs @v1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.0 ↗ · + Follow
614 symbols 1,903 edges 93 files 220 documented · 36% updated 2mo agov1.2.0 · 2025-04-03★ 5,05072 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README


Danfojs: powerful javascript data analysis toolkit

Node.js CI Coverage Status Twitter Patreon donate button

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

  • Danfo.js is fast and supports Tensorflow.js tensors out of the box. This means you can convert Danfo data structure to Tensors.
  • 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, Json, Excel).
  • Powerful, flexible and intutive API for plotting DataFrames and Series interactively.
  • Timeseries-specific functionality: date range generation and date and time properties.
  • Robust data preprocessing functions like OneHotEncoders, LabelEncoders, and scalers like StandardScaler and MinMaxScaler are supported on DataFrame and Series

Installation

There are three ways to install and use Danfo.js in your application * For Nodejs applications, you can install the danfojs-node version via package managers like yarn and/or npm:

npm install danfojs-node

or

yarn add danfojs-node

For client-side applications built with frameworks like React, Vue, Next.js, etc, you can install the danfojs version:

npm install danfojs

or

yarn add danfojs

For use directly in HTML files, you can add the latest script tag from JsDelivr to your HTML file:

    <script src="https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.js"></script>

See all available versions here

Quick Examples

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@1.1.2/lib/bundle.js"></script>

    <title>Document</title>
  </head>

  <body>
















    <script>

      dfd.readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
          .then(df => {

              df['AAPL.Open'].plot("div1").box() //makes a box plot

              df.plot("div2").table() //display csv as table

              new_df = df.setIndex({ column: "Date", drop: true }); //resets the index to Date column
              new_df.head().print() //
              new_df.plot("div3").line({
                  config: {
                      columns: ["AAPL.Open", "AAPL.High"]
                  }
              })  //makes a timeseries plot

          }).catch(err => {
              console.log(err);
          })
    </script>
  </body>
</html>

Output in Browser:

Example usage in Nodejs

const dfd = require("danfojs-node");

const file_url =
  "https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv";
dfd
  .readCSV(file_url)
  .then((df) => {
    //prints the first five columns
    df.head().print();

    // Calculate descriptive statistics for all numerical columns
    df.describe().print();

    //prints the shape of the data
    console.log(df.shape);

    //prints all column names
    console.log(df.columns);

    // //prints the inferred dtypes of each column
    df.ctypes.print();

    //selecting a column by subsetting
    df["Name"].print();

    //drop columns by names
    let cols_2_remove = ["Age", "Pclass"];
    let df_drop = df.drop({ columns: cols_2_remove, axis: 1 });
    df_drop.print();

    //select columns by dtypes
    let str_cols = df_drop.selectDtypes(["string"]);
    let num_cols = df_drop.selectDtypes(["int32", "float32"]);
    str_cols.print();
    num_cols.print();

    //add new column to Dataframe

    let new_vals = df["Fare"].round(1);
    df_drop.addColumn("fare_round", new_vals, { inplace: true });
    df_drop.print();

    df_drop["fare_round"].round(2).print(5);

    //prints the number of occurence each value in the column
    df_drop["Survived"].valueCounts().print();

    //print the last ten elementa of a DataFrame
    df_drop.tail(10).print();

    //prints the number of missing values in a DataFrame
    df_drop.isNa().sum().print();
  })
  .catch((err) => {
    console.log(err);
  });

Output in Node Console:

Notebook support

  • VsCode nodejs notebook extension now supports Danfo.js. See guide here
  • ObservableHQ Notebooks. See example notebook here

See the Official Getting Started Guide

Documentation

The official documentation can be found here

Danfo.js Official Book

We published a book titled "Building Data Driven Applications with Danfo.js". Read more about it here

Discussion and Development

Development discussions take place here.

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.

Licence MIT

Created by Rising Odegua and Stephen Oni

Danfo.js - Open Source JavaScript library for manipulating data. | Product Hunt Embed

Extension points exported contracts — how you extend this code

NDframeInterface (Interface)
(no doc) [2 implementers]
src/danfojs-base/shared/types.ts
SeriesInterface (Interface)
(no doc) [2 implementers]
src/danfojs-base/shared/types.ts
DataFrameInterface (Interface)
(no doc) [2 implementers]
src/danfojs-base/shared/types.ts
DateTime (Interface)
(no doc) [2 implementers]
src/danfojs-base/shared/types.ts
IPlotlyLib (Interface)
(no doc) [2 implementers]
src/danfojs-base/shared/types.ts

Core symbols most depended-on inside this repo

map
called by 145
src/danfojs-base/shared/types.ts
$setValues
called by 101
src/danfojs-base/core/generic.ts
indexOf
called by 81
src/danfojs-base/core/strings.ts
iloc
called by 80
src/danfojs-base/shared/types.ts
loc
called by 66
src/danfojs-base/shared/types.ts
includes
called by 51
src/danfojs-base/core/strings.ts
isEmpty
called by 45
src/danfojs-base/shared/utils.ts
groupby
called by 44
src/danfojs-base/shared/types.ts

Shape

Method 508
Function 53
Class 40
Interface 13

Languages

TypeScript100%

Modules by API surface

src/danfojs-base/shared/types.ts171 symbols
src/danfojs-base/core/frame.ts82 symbols
src/danfojs-base/core/series.ts70 symbols
src/danfojs-base/shared/utils.ts44 symbols
src/danfojs-base/aggregators/groupby.ts30 symbols
src/danfojs-base/core/generic.ts26 symbols
src/danfojs-base/core/strings.ts23 symbols
src/danfojs-base/core/datetime.ts15 symbols
src/danfojs-base/shared/config.ts13 symbols
src/danfojs-base/core/daterange.ts13 symbols
src/danfojs-base/transformers/merge.ts12 symbols
src/danfojs-base/plotting/index.ts12 symbols

Dependencies from manifests, versioned

@babel/cli7.10.5 · 1×
@babel/core7.10.5 · 1×
@babel/plugin-transform-runtime7.12.10 · 1×
@babel/preset-env7.10.4 · 1×
@babel/register7.10.1 · 1×
@tensorflow/tfjs3.13.0 · 1×
@tensorflow/tfjs-node3.13.0 · 1×
@types/chai4.2.19 · 1×
@types/chai-as-promised7.1.5 · 1×
@types/mocha8.2.2 · 1×
@types/node15.12.5 · 1×
@types/papaparse5.2.6 · 1×

For agents

$ claude mcp add danfojs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact