Danfo.js is an open-source JavaScript library designed for data manipulation, analysis, and machine learning. It provides a powerful toolkit for handling structured data in JavaScript, similar to what Pandas offers in Python.
Danfo.js was created to bring data science capabilities to JavaScript developers, allowing them to perform data analysis directly in web browsers and Node.js environments without relying on Python.
The library is built on top of TensorFlow.js, which means it can leverage GPU acceleration and integrate seamlessly with machine learning workflows.
Read and download the Facebook Carousel Post
Why Danfo.js Was Created

Traditionally, data science has been dominated by Python libraries such as:
- Pandas
- NumPy
- Scikit-learn
JavaScript developers often had to switch languages whenever they needed advanced data analysis capabilities.
Danfo.js solves this problem by bringing:
- DataFrames
- Data cleaning
- Data transformation
- Statistical analysis
- Visualization support
- Machine learning integration
directly into JavaScript.
Key Features of Danfo.js
1. DataFrame Support
The DataFrame is the core component of Danfo.js.
A DataFrame organizes data into rows and columns, similar to:
- Excel spreadsheets
- SQL tables
- Pandas DataFrames
Example:
const dfd = require("danfojs-node");
const df = new dfd.DataFrame([
{ Name: "John", Age: 25 },
{ Name: "Jane", Age: 30 }
]);
df.print();
Output:
| Name | Age |
|------|-----|
| John | 25 |
| Jane | 30 |
2. Series Support
A Series represents a single column of data.
Example:
const series = new dfd.Series([10, 20, 30, 40]);
series.print();
Output:
0 10
1 20
2 30
3 40
3. Reading Data from Files
Danfo.js can load data from multiple formats.
CSV Files
const df = await dfd.readCSV("employees.csv");
JSON Files
const df = new dfd.DataFrame(jsonData);
Excel Files
const df = await dfd.readExcel("employees.xlsx");
This makes it easy to work with real-world datasets.
4. Viewing Data
First Rows
df.head();
Last Rows
df.tail();
Shape
df.shape;
Example output:
[1000, 15]
Meaning:
- 1000 rows
- 15 columns
5. Selecting Columns
Select a single column:
df["Age"];
Select multiple columns:
df.loc({
columns: ["Name", "Age"]
});
6. Filtering Data
Example:
const result = df.query(df["Age"].gt(30));
result.print();
Output:
Employees older than 30
Filtering is essential for data exploration.
7. Handling Missing Values
Real-world datasets often contain missing values.
Danfo.js provides several methods.
Check Missing Values
df.isNa().sum();
Remove Missing Values
df.dropNa();
Fill Missing Values
df.fillNa(0);
8. Statistical Analysis
Danfo.js includes built-in statistical functions.
Mean
df["Salary"].mean();
Median
df["Salary"].median();
Maximum
df["Salary"].max();
Minimum
df["Salary"].min();
Standard Deviation
df["Salary"].std();
These functions are useful for exploratory data analysis (EDA).
9. Sorting Data
Ascending order:
df.sortValues("Salary");
Descending order:
df.sortValues("Salary", {
ascending: false
});
10. GroupBy Operations
Grouping allows aggregation of data.
Example:
df.groupby(["Department"]).sum();
Output:
Department-wise totals
Other aggregations include:
- Sum
- Mean
- Count
- Max
- Min
- Variance
11. Data Cleaning
Data cleaning is one of the most important aspects of data science.
Danfo.js supports:
Renaming Columns
df.rename({
mapper: {
Salary: "AnnualSalary"
},
axis: 1
});
Removing Columns
df.drop({
columns: ["Address"]
});
Removing Duplicate Rows
df.dropDuplicates();
12. Data Transformation
Transform existing columns.
Example:
df.addColumn(
"Tax",
df["Salary"].mul(0.1)
);
This creates a new column containing 10% tax values.
13. Merging DataFrames
Like SQL JOIN operations.
Inner Join
df1.merge(df2, {
on: ["EmployeeID"],
how: "inner"
});
Left Join
df1.merge(df2, {
on: ["EmployeeID"],
how: "left"
});
14. Machine Learning Integration
Since Danfo.js is built on TensorFlow.js, it can integrate directly with machine learning workflows.
Example:
const tensor = df.tensor;
Convert DataFrame data into TensorFlow tensors for training models.
Applications include:
- Regression
- Classification
- Clustering
- Neural Networks
- Deep Learning
15. Visualization Support
Danfo.js supports plotting through various visualization libraries.
Common chart types:
- Line charts
- Bar charts
- Histograms
- Pie charts
- Scatter plots
Example:
df.plot("divId").bar();
Danfo.js in the Browser
One of Danfo.js’ greatest strengths is browser support.
Install:
<script src="https://cdn.jsdelivr.net/npm/danfojs@latest/lib/bundle.min.js"></script>
Example:
const df = new dfd.DataFrame([
{ Product: "Laptop", Sales: 120 },
{ Product: "Phone", Sales: 300 }
]);
df.print();
This enables client-side data analytics without sending data to a server.
Danfo.js in Node.js
Installation:
npm install danfojs-node
Usage:
const dfd = require("danfojs-node");
Node.js support makes Danfo.js suitable for:
- ETL pipelines
- Data processing scripts
- Analytics dashboards
- Backend reporting systems
- AI applications
Advantages of Danfo.js
Familiar Pandas-Like API
Python developers can quickly adapt.
Full JavaScript Ecosystem Integration
Works naturally with:
- Node.js
- React
- Next.js
- Express
- TensorFlow.js
Browser and Server Support
Write data analysis code once and run it anywhere.
Open Source
Free to use and modify.
GPU Acceleration
Benefits from TensorFlow.js backend optimizations.
Limitations of Danfo.js
Smaller Ecosystem
The ecosystem is much smaller than Python’s Pandas.
Fewer Learning Resources
There are fewer tutorials, courses, and community examples.
Performance Constraints
For extremely large datasets, Python libraries such as Pandas, Polars, or Spark may still offer better scalability.
Limited Enterprise Adoption
Most enterprise data science teams still primarily use Python.
Common Use Cases
Data Analysis Dashboards
Analyzing business metrics directly in web applications.
Financial Applications
Processing transaction data and generating reports.
Educational Platforms
Teaching data science concepts using JavaScript.
Machine Learning Pipelines
Preparing data before model training.
Real-Time Analytics
Analyzing streaming data in browser-based applications.
Data Cleaning
Cleaning imported CSV and Excel files.
Danfo.js vs Pandas
| Feature | Danfo.js | Pandas |
|---|---|---|
| Language | JavaScript | Python |
| DataFrames | ✓ | ✓ |
| GroupBy | ✓ | ✓ |
| Missing Data Handling | ✓ | ✓ |
| Visualization | ✓ | ✓ |
| Machine Learning Integration | TensorFlow.js | Scikit-learn/TensorFlow |
| Browser Support | ✓ | ✗ |
| Ecosystem Size | Smaller | Massive |
| Community | Growing | Very Large |
When Should You Use Danfo.js?
Danfo.js is an excellent choice when:
- Your project is entirely JavaScript-based.
- You want data analysis directly in the browser.
- You are building React or Next.js analytics applications.
- You need seamless integration with TensorFlow.js.
- You want Pandas-like functionality without switching to Python.
For heavy-duty data science, large-scale analytics, or enterprise machine learning pipelines, Python ecosystems such as Pandas, NumPy, and Scikit-learn still offer a broader range of tools.
Conclusion
Danfo.js brings the power of data science to JavaScript by providing DataFrames, data cleaning tools, statistical analysis, data transformation, visualization, and machine learning integration. It effectively serves as the “Pandas of JavaScript,” enabling developers to perform sophisticated data analysis in both browsers and Node.js environments. For JavaScript developers building analytics platforms, dashboards, AI applications, or educational tools, Danfo.js is one of the most powerful and practical libraries available today.

Latest tech news and coding tips.