Using Danfojs in React
TL:DR See Example react application using danfojs here
Danfojs works for both browser and NodeJs environment, and as such is available to frontend frameworks like React and Vue.
In order to use Danfojs in a library like React, you must install the browser side version from npm.
1
npm install danfojs
2
3
or
4
5
yarn add danfojs
Copied!
Follow the steps here to bootstrap a React app, and in your App.js or any file where you want to use danfojs, you can import it as follow:
1
import "./App.css";
2
import * as dfd from "danfojs/src/index";
Copied!
Now you have access to all features under the dfd namespace. Below is a sample App.js file using danfojs:
1
import "./App.css";
2
import * as dfd from "danfojs/src/index";
3
4
function App() {
5
6
const df = new dfd.DataFrame(
7
{ pig: [20, 18, 489, 675, 1776], horse: [4, 25, 281, 600, 1900] },
8
{ index: [1990, 1997, 2003, 2009, 2014] }
9
);
10
df.head().print()
11
12
13
return (
14
<div className="App">
15
<header className="App-header">
16
<a
17
className="App-link"
18
href="https://danfo.jsdata.org/getting-started"
19
target="_blank"
20
rel="noopener noreferrer"
21
>
22
Learn Danfojs
23
</a>
24
</header>
25
</div>
26
);
27
}
28
29
export default App;
30
Copied!
On running the app, we get the following output in the console:
Note that you can also import specific modules. For instance, in the code below we import only the DataFrame module:
1
import { DataFrame } from "danfojs/src/index";
Copied!
Following these steps, you can use danfojs in any client-side library.
Last modified 4mo ago
Copy link