Danfojs — A pandas like Library

HackerDev
3 min readNov 28, 2020

Introduction to Data Visualization with Danfo.js

Danfo.js is heavily inspired by the Pandas library and provides a similar interface and API. This means users familiar with the Pandas API can easily use Danfo.js.

Main Features

Danfo.js is fast. It is built on Tensorflow.js, and supports 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 and delimited) and JSON data format.

Powerful, flexible and intuitive 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.

To learn more about Danfo.js click here

Lets Begin

In this article we be covering how to read csv, plot line graph, plotting specific columns.

To begin

Step 1

npm init -y

Create two files index.html and index.js

Install Danfo js

npm i danfojs-node

or use

<script src=”https://cdn.jsdelivr.net/npm/danfojs@0.1.2/dist/index.min.js"></script>

Step 2

Paste the below html into index.html

Now paste the js code to index.js

The read_csv method can read csv from internet or from local drive and it return a promise. plot() method is called on Series and DataFrame. The .plot() method accepts an HTML Div id where it renders the plot, while configuration options for the lines drawn can be passed through the config parameter.

The above code will plot the following Line Graph

plotting all columns in line graph

Line graph for a specific columns. In this case Open and Close

Conclusion

Danfo.js is an open-source, JavaScript library providing high-performance, intuitive, and easy-to-use data structures for manipulating and processing structured data.

Find out more about Danfo.js

--

--

HackerDev
0 Followers

Hacker by night, developer by day.