|
| 1 | + |
| 2 | +<div align="center"> |
| 3 | + <img src="assets/logo.png"><br> |
| 4 | +</div> |
| 5 | + |
| 6 | +----------------- |
| 7 | + |
| 8 | +## Danfojs: powerful javascript data analysis toolkit |
| 9 | + |
| 10 | +[](https://www.jsdelivr.com/package/npm/danfojs) |
| 11 | +[](https://coveralls.io/github/opensource9ja/danfojs) |
| 12 | + |
| 13 | +<span class="badge-patreon"><a href="https://www.patreon.com/bePatron?u=40496758" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span> |
| 14 | + |
| 15 | + |
| 16 | +## What is it? |
| 17 | + |
| 18 | +**Danfo.js** is a javascript package that provides fast, flexible, and expressive data |
| 19 | +structures designed to make working with "relational" or "labeled" data both |
| 20 | +easy and intuitive. It is heavily inspired by [Pandas](https://pandas.pydata.org/pandas-docs/stable/) library, and provides a similar API. This means that users familiar with [Pandas](https://pandas.pydata.org/pandas-docs/stable/), can easily pick up danfo.js. |
| 21 | + |
| 22 | +## Main Features |
| 23 | + |
| 24 | + - 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](https://danfo.jsdata.org/api-reference/dataframe/dataframe.tensor) to Tensors. |
| 25 | + - Easy handling of [missing-data](https://danfo.jsdata.org/getting-started#missing-data) (represented as |
| 26 | + `NaN`) in floating point as well as non-floating point data |
| 27 | + - Size mutability: columns can be [inserted/deleted](https://danfo.jsdata.org/api-reference/dataframe#combining-comparing-joining-merging) from DataFrame |
| 28 | + - Automatic and explicit [alignment](https://danfo.jsdata.org/api-reference/dataframe#reindexing-selection-label-manipulation): objects can |
| 29 | + be explicitly aligned to a set of labels, or the user can simply |
| 30 | + ignore the labels and let `Series`, `DataFrame`, etc. automatically |
| 31 | + align the data for you in computations |
| 32 | + - Powerful, flexible [groupby](https://danfo.jsdata.org/api-reference/groupby) functionality to perform |
| 33 | + split-apply-combine operations on data sets, for both aggregating |
| 34 | + and transforming data |
| 35 | + - Make it easy to convert Arrays, JSONs, List or Objects, Tensors and |
| 36 | + differently-indexed data structures |
| 37 | + into DataFrame objects |
| 38 | + - Intelligent label-based [slicing](https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.loc), [fancy indexing](https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.iloc), and [querying](https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.query) of |
| 39 | + large data sets |
| 40 | + - Intuitive [merging](https://danfo.jsdata.org/api-reference/general-functions/danfo.merge) and [joining](https://danfo.jsdata.org/api-reference/general-functions/danfo.concat) data |
| 41 | + sets |
| 42 | + - Robust IO tools for loading data from [flat-files](https://danfo.jsdata.org/api-reference/input-output) |
| 43 | + (CSV, Json, Excel, Data package). |
| 44 | + - Powerful, flexible and intutive API for [plotting](https://danfo.jsdata.org/api-reference/plotting) DataFrames and Series interactively. |
| 45 | + - [Timeseries](https://danfo.jsdata.org/api-reference/series#accessors)-specific functionality: date range |
| 46 | + generation and date and time properties. |
| 47 | + - Robust data preprocessing functions like [OneHotEncoders](https://danfo.jsdata.org/api-reference/general-functions/danfo.onehotencoder), [LabelEncoders](https://danfo.jsdata.org/api-reference/general-functions/danfo.labelencoder), and scalers like [StandardScaler](https://danfo.jsdata.org/api-reference/general-functions/danfo.standardscaler) and [MinMaxScaler](https://danfo.jsdata.org/api-reference/general-functions/danfo.minmaxscaler) are supported on DataFrame and Series |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +To use Danfo.js via script tags, copy and paste the CDN below to the body of your HTML file |
| 52 | + |
| 53 | +```html |
| 54 | + <script src="https://cdn.jsdelivr.net/npm/danfojs@0.2.3/lib/bundle.min.js"></script> |
| 55 | +``` |
| 56 | + |
| 57 | +### Example Usage in the Browser |
| 58 | + |
| 59 | +> See the example below in [Code Sandbox](https://codepen.io/risingodegua/pen/bGwPGMG) |
| 60 | +
|
| 61 | +```html |
| 62 | + |
| 63 | +<!DOCTYPE html> |
| 64 | +<html lang="en"> |
| 65 | +<head> |
| 66 | + <meta charset="UTF-8"> |
| 67 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 68 | + <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> |
| 69 | + <script src="https://cdn.jsdelivr.net/npm/danfojs@0.2.3/lib/bundle.min.js"></script> |
| 70 | + |
| 71 | + <title>Document</title> |
| 72 | +</head> |
| 73 | + |
| 74 | +<body> |
| 75 | + |
| 76 | + <div id="div1"></div> |
| 77 | + <div id="div2"></div> |
| 78 | + <div id="div3"></div> |
| 79 | + |
| 80 | + <script> |
| 81 | +
|
| 82 | + dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") |
| 83 | + .then(df => { |
| 84 | +
|
| 85 | + df['AAPL.Open'].plot("div1").box() //makes a box plot |
| 86 | +
|
| 87 | + df.plot("div2").table() //display csv as table |
| 88 | +
|
| 89 | + new_df = df.set_index({ key: "Date" }) //resets the index to Date column |
| 90 | + new_df.plot("div3").line({ columns: ["AAPL.Open", "AAPL.High"] }) //makes a timeseries plot |
| 91 | +
|
| 92 | + }).catch(err => { |
| 93 | + console.log(err); |
| 94 | + }) |
| 95 | +
|
| 96 | + </script> |
| 97 | + |
| 98 | +</body> |
| 99 | + |
| 100 | +</html> |
| 101 | +``` |
| 102 | + |
| 103 | +Output in Browser: |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +## How to install |
| 108 | +Danfo.js is hosted on NPM, and can installed via package managers like npm and yarn |
| 109 | + |
| 110 | +```sh |
| 111 | +npm install danfojs-node |
| 112 | +``` |
| 113 | + |
| 114 | +### Example usage in Nodejs |
| 115 | + |
| 116 | +```javascript |
| 117 | + |
| 118 | +const dfd = require("danfojs-node") |
| 119 | + |
| 120 | + |
| 121 | +dfd.read_csv("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") |
| 122 | + .then(df => { |
| 123 | + //prints the first five columns |
| 124 | + df.head().print() |
| 125 | + |
| 126 | + //Calculate descriptive statistics for all numerical columns |
| 127 | + df.describe().print() |
| 128 | + |
| 129 | + //prints the shape of the data |
| 130 | + console.log(df.shape); |
| 131 | + |
| 132 | + //prints all column names |
| 133 | + console.log(df.column_names); |
| 134 | + |
| 135 | + //prints the inferred dtypes of each column |
| 136 | + df.ctypes.print() |
| 137 | + |
| 138 | + //selecting a column by subsetting |
| 139 | + df['Name'].print() |
| 140 | + |
| 141 | + //drop columns by names |
| 142 | + cols_2_remove = ['Age', 'Pclass'] |
| 143 | + df_drop = df.drop({ columns: cols_2_remove, axis: 1 }) |
| 144 | + df_drop.print() |
| 145 | + |
| 146 | + |
| 147 | + //select columns by dtypes |
| 148 | + let str_cols = df_drop.select_dtypes(["string"]) |
| 149 | + let num_cols = df_drop.select_dtypes(["int32", "float32"]) |
| 150 | + str_cols.print() |
| 151 | + num_cols.print() |
| 152 | + |
| 153 | + |
| 154 | + //add new column to Dataframe |
| 155 | + let new_vals = df['Fare'].round().values |
| 156 | + df_drop.addColumn({ column: "fare_round", value: new_vals}) |
| 157 | + df_drop.print() |
| 158 | + |
| 159 | + df_drop['fare_round'].print(5) |
| 160 | + |
| 161 | + //prints the number of occurence each value in the column |
| 162 | + df_drop['Survived'].value_counts().print() |
| 163 | + |
| 164 | + //print the last ten elementa of a DataFrame |
| 165 | + df_drop.tail(10).print() |
| 166 | + |
| 167 | + //prints the number of missing values in a DataFrame |
| 168 | + df_drop.isna().sum().print() |
| 169 | + |
| 170 | + }).catch(err => { |
| 171 | + console.log(err); |
| 172 | + }) |
| 173 | + |
| 174 | +``` |
| 175 | +Output in Node Console: |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | +> If you want to use Danfo in frontend frameworks like React/Vue, read this [guide](https://danfo.jsdata.org/examples/using-danfojs-in-react) |
| 180 | +
|
| 181 | +#### You can play with Danfo.js on Dnotebooks playground [here](https://playnotebook.jsdata.org/demo) |
| 182 | + |
| 183 | +#### [See the Official Getting Started Guide](https://danfo.jsdata.org/getting-started) |
| 184 | + |
| 185 | +## Documentation |
| 186 | +The official documentation can be found [here](https://danfo.jsdata.org) |
| 187 | + |
| 188 | +## Discussion and Development |
| 189 | +Development discussions take place on our [issues](https://github.com/opensource9ja/danfojs/issues) tab. |
| 190 | + |
| 191 | +## Contributing to Danfo |
| 192 | +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](https://danfo.jsdata.org/contributing-guide). |
| 193 | + |
| 194 | +#### Licence [MIT](https://github.com/opensource9ja/danfojs/blob/master/LICENCE) |
| 195 | + |
| 196 | +#### Created by [Rising Odegua](https://github.com/risenW) and [Stephen Oni](https://github.com/steveoni) |
| 197 | + |
| 198 | +<a href="https://www.producthunt.com/posts/danfo-js?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-danfo-js" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=233871&theme=light" alt="Danfo.js - Open Source JavaScript library for manipulating data. | Product Hunt Embed" style="width: 250px; height: 54px;" width="250px" height="54px" /></a> |
0 commit comments