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
Traditionally, data science has been dominated by Python libraries such as:
JavaScript developers often had to switch languages whenever they needed advanced data analysis capabilities.
Danfo.js solves this problem by bringing:
directly into JavaScript.
The DataFrame is the core component of Danfo.js.
A DataFrame organizes data into rows and columns, similar to:
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 |
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 Danfo.js can load data from multiple formats.
const df = await dfd.readCSV("employees.csv"); const df = new dfd.DataFrame(jsonData); const df = await dfd.readExcel("employees.xlsx"); This makes it easy to work with real-world datasets.
df.head(); df.tail(); df.shape; Example output:
[1000, 15] Meaning:
Select a single column:
df["Age"]; Select multiple columns:
df.loc({
columns: ["Name", "Age"]
}); Example:
const result = df.query(df["Age"].gt(30));
result.print(); Output:
Employees older than 30 Filtering is essential for data exploration.
Real-world datasets often contain missing values.
Danfo.js provides several methods.
df.isNa().sum(); df.dropNa(); df.fillNa(0); Danfo.js includes built-in statistical functions.
df["Salary"].mean(); df["Salary"].median(); df["Salary"].max(); df["Salary"].min(); df["Salary"].std(); These functions are useful for exploratory data analysis (EDA).
Ascending order:
df.sortValues("Salary"); Descending order:
df.sortValues("Salary", {
ascending: false
}); Grouping allows aggregation of data.
Example:
df.groupby(["Department"]).sum(); Output:
Department-wise totals Other aggregations include:
Data cleaning is one of the most important aspects of data science.
Danfo.js supports:
df.rename({
mapper: {
Salary: "AnnualSalary"
},
axis: 1
}); df.drop({
columns: ["Address"]
}); df.dropDuplicates(); Transform existing columns.
Example:
df.addColumn(
"Tax",
df["Salary"].mul(0.1)
); This creates a new column containing 10% tax values.
Like SQL JOIN operations.
df1.merge(df2, {
on: ["EmployeeID"],
how: "inner"
}); df1.merge(df2, {
on: ["EmployeeID"],
how: "left"
}); 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:
Danfo.js supports plotting through various visualization libraries.
Common chart types:
Example:
df.plot("divId").bar(); 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.
Installation:
npm install danfojs-node Usage:
const dfd = require("danfojs-node"); Node.js support makes Danfo.js suitable for:
Python developers can quickly adapt.
Works naturally with:
Write data analysis code once and run it anywhere.
Free to use and modify.
Benefits from TensorFlow.js backend optimizations.
The ecosystem is much smaller than Python’s Pandas.
There are fewer tutorials, courses, and community examples.
For extremely large datasets, Python libraries such as Pandas, Polars, or Spark may still offer better scalability.
Most enterprise data science teams still primarily use Python.
Analyzing business metrics directly in web applications.
Processing transaction data and generating reports.
Teaching data science concepts using JavaScript.
Preparing data before model training.
Analyzing streaming data in browser-based applications.
Cleaning imported CSV and Excel files.
| 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 |
Danfo.js is an excellent choice when:
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.
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.
JavaScript's async and await keywords revolutionized asynchronous programming by making asynchronous code look and behave more like synchronous code.…
Pretty Good Privacy (PGP) is one of the most widely used encryption systems for securing emails,…
Database migration is one of the most challenging tasks in software engineering. While both PostgreSQL…
Modern JavaScript isn’t just let, const, arrow functions, and promises anymore. Over the years, the language has…
Software development is one of the most rewarding careers in technology, but it is also…
Printing a document in JavaScript usually means triggering the browser’s print dialog and controlling what…