# Danfo.js Documentation

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

D**anfo.js** is heavily inspired by the [Pandas](https://pandas.pydata.org/pandas-docs/stable/index.html) library and provides a similar interface and API. This means users familiar with the [Pandas ](https://pandas.pydata.org/pandas-docs/stable/index.html)API can easily use D**anfo.js.**

## Main Features

* Danfo.js is fast and supports[ Tensorflow.js](https://js.tensorflow.org)'s tensors out of the box. This means you can [convert Danfo.js ](/api-reference/dataframe)DataFrames to Tensors, and vice versa.
* Easy handling of missing data (represented as `NaN, undefined, or null`) in data
* Size mutability: columns can be inserted/deleted from DataFrames
* 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`](/api-reference/series), [`DataFrame`](/api-reference/dataframe), etc. automatically align the data for you in computations
* Powerful, flexible, [groupby](/api-reference/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](/api-reference/general-functions/danfo.merge) and [joining](/api-reference/general-functions/danfo.concat) data sets
* Robust IO tools for loading data from [flat-files](/api-reference/input-output/danfo.read_csv) (CSV and delimited), Excel, and JSON data format.
* Powerful, flexible, and intiutive API for [plotting](https://app.gitbook.com/@jsdata/s/danfojs/~/drafts/-MESZnq3_VBU0EW71MxS/api-reference/plotting) DataFrames and Series interactively.
* Timeseries-specific functionality: date range generation and date and time properties.
* Robust data preprocessing functions like [OneHotEncoders](/api-reference/general-functions/danfo.onehotencoder), [LabelEncoders](/api-reference/general-functions/danfo.labelencoder), and scalers like [StandardScaler](/api-reference/general-functions/danfo.standardscaler) and [MinMaxScaler](/api-reference/general-functions/danfo.minmaxscaler) are supported on DataFrame and Series

## Getting Started

New to Danfo? Check out the getting started guides. It contains a quick introduction to D\_anfo's\_ main concepts and links to additional content.

{% content-ref url="/pages/-MDu9wFmXxB4IoYAO6R\_" %}
[Getting Started](/getting-started)
{% endcontent-ref %}

## **API Reference**

The reference guide contains a detailed description of the **danfo** API. The reference describes how each function works and which parameters can be used.

{% content-ref url="/pages/-MB6W-03\_cNQ3LxfB2\_S" %}
[API reference](/api-reference)
{% endcontent-ref %}

## User Guides/Tutorials

{% content-ref url="/pages/-MEi4CrRaNqLzqrANwdU" %}
[User Guides](/examples)
{% endcontent-ref %}

## Building Data Driven Applications with Danfo.js - Book

{% content-ref url="/pages/-MjTMTRb0z4eG\_2wVz99" %}
[Building Data Driven Applications with Danfo.js - Book](/building-data-driven-applications-with-danfo.js-book)
{% endcontent-ref %}

## Contributing Guide

Want to help improve our documentation and existing functionalities? The contributing guidelines will guide you through the process.

{% content-ref url="/pages/-MDuLPJpehtmq5YbLLm7" %}
[Contributing Guide](/contributing-guide)
{% endcontent-ref %}

## Release Notes

{% content-ref url="/pages/-MEmTsIPGMd\_H6JAOlt9" %}
[Release Notes](/release-notes)
{% endcontent-ref %}


# Getting Started

Installation guides for Node and Browser based environments, including a quick 10 minute walk through of danfo.js

{% hint style="info" %}
A stable version of Danfojs (v1), has been released, and it comes with full Typescript support, new features, and many bug fixes. See release note [here](https://danfo.jsdata.org/pages/-MEmTsIPGMd_H6JAOlt9#latest-release-node-v1.0.0-browser-v1.0.0).

There are a couple of breaking changes, so we have prepared a short migration [guide](/examples/migrating-to-the-stable-version-of-danfo.js) for pre-v1 users.
{% endhint %}

## Installation

There are three ways to install and use Danfo.js in your application

For Nodejs applications, you can install the [danfojs-node](https://www.npmjs.com/package/danfojs-node) version via package managers like yarn and npm:

```
npm install danfojs-node

or

yarn add danfojs-node
```

For client-side applications built with frameworks like React, Vue, Next.js, etc, you can install the [danfojs](https://www.npmjs.com/package/danfojs) version:

```
npm install danfojs

or

yarn add danfojs
```

For use directly in HTML files, you can add the latest script tag from [JsDelivr](https://www.jsdelivr.com/package/npm/danfojs):

```markup
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
```

{% hint style="info" %}
To play with Danfo.js in a Notebook-like environment, see [Dnotebooks](https://dnotebook.jsdata.org/getting-started) [here](https://playnotebook.jsdata.org/demo) or the [VS-Code Nodejs notebook extension](https://marketplace.visualstudio.com/items?itemName=donjayamanne.typescript-notebook).
{% endhint %}

## 10 minutes to danfo.js

This is a short introduction to Danfo.js, and its flow is adapted from the official [10 minutes to Pandas](https://pandas.pydata.org/pandas-docs/stable/user_guide/10min.html#min)

We will show you how to use danfo.js in a browser, client-side libraries, and Node.js environments. Most functions except [plotting](https://jsdata.gitbook.io/danfojs/api-reference/plotting) which require a DOM work the same way in all environments.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

//or using ES6
import * as dfd from "danfojs-node"
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
</head>

<body>

    <script>

      //danfo is exposed on dfd namespace 
      s = new dfd.Series([1,2,3,4,5]) 

    </script>

</body>

</html>
```

{% endtab %}

{% tab title="React" %}

```jsx
import * as dfd from "danfojs"

//import specific methods/classes
import { readCSV, DataFrame } from "danfojs"
```

{% endtab %}
{% endtabs %}

### Creating a DataFrame/Series

You can create a [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) by passing a list of values, letting Danfo.js create a default integer index:

{% tabs %}
{% tab title="Node" %}

```javascript
import * as dfd from "danfojs-node"

s = new dfd.Series([1, 3, 5, undefined, 6, 8])
s.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

        s = new dfd.Series([1, 3, 5, undefined, 6, 8])
        s.print()

    </script>

</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 1                    ║
╟───┼──────────────────────╢
║ 1 │ 3                    ║
╟───┼──────────────────────╢
║ 2 │ 5                    ║
╟───┼──────────────────────╢
║ 3 │ undefined            ║
╟───┼──────────────────────╢
║ 4 │ 6                    ║
╟───┼──────────────────────╢
║ 5 │ 8                    ║
╚═══╧══════════════════════╝
```

Creating a [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) from a tensor

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
const tf = dfd.tensorflow //Tensorflow.js is exportedfrom Danfojs


let tensor_arr = tf.tensor([12,34,56,2])
let s = new dfd.Series(tensor_arr)
s.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>

    <title>Document</title>
</head>

<body>

    <script>
        const tf = dfd.tensorflow //get tensorflow lib from danfo
        let tensor_arr = tf.tensor([12,34,56,2])
        let s = new dfd.Series(tensor_arr)
        s.print()

    </script>

</body>

</html>
```

{% endtab %}
{% endtabs %}

```
╔═══╤════╗
║ 0 │ 12 ║
╟───┼────╢
║ 1 │ 34 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 3 │ 2  ║
╚═══╧════╝
```

Creating a [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) by passing a JSON object:

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
            { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
            { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
            { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

df = new dfd.DataFrame(json_data)
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
<title>Document</title>
</head>

<body>

    <script>

         json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
            { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
            { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
            { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

Creating a [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) from a 2D tensor

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
const tf = dfd.tensorflow //Tensorflow.js is exported from Danfojs


let tensor_arr = tf.tensor2d([[12, 34, 2.2, 2], [30, 30, 2.1, 7]])
let df = new dfd.DataFrame(tensor_arr, {columns: ["A", "B", "C", "D"]})
df.print()
df.ctypes.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

         json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
            { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
            { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
            { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 12                │ 34                │ 2.20000004768...  │ 2                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30                │ 30                │ 2.09999990463...  │ 7                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ A │ int32                ║
╟───┼──────────────────────╢
║ B │ int32                ║
╟───┼──────────────────────╢
║ C │ float32              ║
╟───┼──────────────────────╢
║ D │ int32                ║
╚═══╧══════════════════════╝
```

Creating a [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) by passing a dictionary of objects with the same length

{% tabs %}
{% tab title="Nodejs" %}

```javascript
const dfd = require("danfojs-node")

// Danfojs v1.0.0 and above
dates = new dfd.dateRange({ start: '2017-01-01', end: "2020-01-01", period: 4, freq: "Y" })

console.log(dates);

obj_data = {'A': dates,
            'B': ["bval1", "bval2", "bval3", "bval4"],
            'C': [10, 20, 30, 40],
            'D': [1.2, 3.45, 60.1, 45],
            'E': ["test", "train", "test", "train"]
            }

df = new dfd.DataFrame(obj_data)
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

        dates = new dfd.dateRange({ start: '2017-01-01', end: "2020-01-01", period: 4, freq: "Y" })

        console.log(dates);

        obj_data = {'A': dates,
                    'B': ["bval1", "bval2", "bval3", "bval4"],
                    'C': [10, 20, 30, 40],
                    'D': [1.2, 3.45, 60.1, 45],
                    'E': ["test", "train", "test", "train"]
                    }

        df = new dfd.DataFrame(obj_data)
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output in console
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 │ D                 │ E                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 1/1/2017, 1:0...  │ bval1             │ 10                │ 1.2               │ test              ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 1/1/2018, 1:0...  │ bval2             │ 20                │ 3.45              │ train             ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 1/1/2019, 1:0...  │ bval3             │ 30                │ 60.1              │ test              ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 1/1/2020, 1:0...  │ bval4             │ 40                │ 45                │ train             ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

The columns of the resulting [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) have different [dtypes](https://pandas.pydata.org/pandas-docs/stable/user_guide/basics.html#basics-dtypes).

```javascript
df.ctypes.print()
```

```
//output
╔═══╤═════════╗
║ A │ string  ║
╟───┼─────────╢
║ B │ string  ║
╟───┼─────────╢
║ C │ int32   ║
╟───┼─────────╢
║ D │ float32 ║
╟───┼─────────╢
║ E │ string  ║
╚═══╧═════════╝
```

Creating a [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) by passing an array of arrays. Index and column labels are automatically generated for you.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

arr_data = [["bval1", 10, 1.2, "test"],
            ["bval2", 20, 3.45, "train"],
            ["bval3", 30, 60.1, "train"],
            ["bval4", 35, 3.2, "test"]]

df = new dfd.DataFrame(arr_data)
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

        arr_data = [["bval1", 10, 1.2, "test"],
            ["bval2", 20, 3.45, "train"],
            ["bval3", 30, 60.1, "train"],
            ["bval4", 35, 3.2, "test"]]

        df = new dfd.DataFrame(arr_data)
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output in console

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ bval1             │ 10                │ 1.2               │ test              ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ bval2             │ 20                │ 3.45              │ train             ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ bval3             │ 30                │ 60.1              │ train             ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ bval4             │ 35                │ 3.2               │ test              ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

### Viewing data

Here is how to view the top and bottom rows of the frame above:

```
df.head(2).print()
df.tail(2).print()
```

```
//output from head
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ bval1             │ 10                │ 1.2               │ test              ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ bval2             │ 20                │ 3.45              │ train             ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


//output from tail

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ bval3             │ 30                │ 60.1              │ train             ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ bval4             │ 35                │ 3.2               │ test              ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Display the index, columns:

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const dfd = require('danfojs-node')

let dates = new dfd.dateRange({
    start: "2017-01-01",
    end: "2020-01-01",
    period: 4,
    freq: "Y",
  });

  let obj_data = {
    A: dates,
    B: ["bval1", "bval2", "bval3", "bval4"],
    C: [10, 20, 30, 40],
    D: [1.2, 3.45, 60.1, 45],
    E: ["test", "train", "test", "train"],
  };

  let df = new dfd.DataFrame(obj_data);
  df.print();
  console.log(df.index);
  console.log(df.columns);
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

      let dates = new dfd.dateRange({
        start: "2017-01-01",
        end: "2020-01-01",
        period: 4,
        freq: "Y",
      });

      let obj_data = {
        A: dates,
        B: ["bval1", "bval2", "bval3", "bval4"],
        C: [10, 20, 30, 40],
        D: [1.2, 3.45, 60.1, 45],
        E: ["test", "train", "test", "train"],
      };

      let df = new dfd.DataFrame(obj_data);
      df.print();
      console.log(df.index);
      console.log(df.columns)
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 │ D                 │ E                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1/1/2017, 1:00:…  │ bval1             │ 10                │ 1.2               │ test              ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 1/1/2018, 1:00:…  │ bval2             │ 20                │ 3.45              │ train             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 1/1/2019, 1:00:…  │ bval3             │ 30                │ 60.1              │ test              ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 1/1/2020, 1:00:…  │ bval4             │ 40                │ 45                │ train             ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

[ 0, 1, 2, 3 ]
[ 'A', 'B', 'C', 'D', 'E' ]
```

[`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy) returns a Tensorflow tensor representation of the underlying data. Note that **Tensorflow tensors have one dtype for the entire array, while danfo DataFrames have one dtype per column**.

For `df`, our [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) of all floating-point values, [`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy)is fast and doesn’t require copying data.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


j son_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
{ A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
{ A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
{ A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

let  df = new dfd.DataFrame(json_data)

console.log(df.tensor);
//or
df.tensor.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

        json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
        { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
        { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
        { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)

        console.log(df.tensor);
        //or
        df.tensor.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output

Tensor {
  kept: false,
  isDisposedInternal: false,
  shape: [ 4, 4 ],
  dtype: 'float32',
  size: 16,
  strides: [ 4 ],
  dataId: {},
  id: 0,
  rankType: '2'
}

Tensor
    [[0.4612, 4.2828302, -1.5089999, -1.1352  ],
     [0.5112, -0.22863 , -3.39059  , 1.1632   ],
     [0.6911, -0.82863 , -1.5059   , 2.1352   ],
     [0.4692, -1.28863 , 4.5058999 , 4.1631999]]
```

**Note**

[`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy) does *not* include the index or column labels in the output.

[`describe()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.describe.html#pandas.DataFrame.describe) shows a quick statistic summary of your data:

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
{ A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
{ A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
{ A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

let df = new dfd.DataFrame(json_data)

df.describe().print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

        json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
                    { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
                    { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
                    { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)

        df.describe().print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output in console

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 │ D                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ count      │ 4                 │ 4                 │ 4                 │ 4                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ mean       │ 0.533175          │ 0.4842349999999…  │ -0.474897500000…  │ 1.5816            ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ std        │ 0.1075428712963…  │ 2.5693167249095…  │ 3.4371471031498…  │ 2.2005448052698…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ min        │ 0.4612            │ -1.28863          │ -3.39059          │ -1.1352           ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ median     │ 0.4901999999999…  │ -0.528629999999…  │ -1.50745          │ 1.6492            ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ max        │ 0.6911            │ 4.28283           │ 4.5059            │ 4.1632            ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ variance   │ 0.0115654691666…  │ 6.6013884328999…  │ 11.813980208691…  │ 4.84239744        ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Sorting by values (Defaults to ascending):

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs")

let data = {"A": [-20, 30, 47.3, NaN],
             "B": [34, -4, 5, 6] ,
             "C": [20, 2, 3, 30] }


let df = new dfd.DataFrame(data)
df.sortValues("C", {inplace: true})
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

        let data = {"A": [-20, 30, 47.3, NaN],
             "B": [34, -4, 5, 6] ,
             "C": [20, 2, 3, 30] }


        let df = new dfd.DataFrame(data)
        df.sortValues("C", {inplace: true})
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 30                │ -4                │ 2                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 47.3              │ 5                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ -20               │ 34                │ 20                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ NaN               │ 6                 │ 30                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

### Selection

#### Getting

Selecting a single column, which yields a [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series), equivalent to `df.A`:

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
{ A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
{ A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
{ A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

df = new dfd.DataFrame(json_data)

df['A'].print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>


        json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
                    { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
                    { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
                    { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)

        df['A'].print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//output
╔═══╤══════════════════════╗
║   │ A                    ║
╟───┼──────────────────────╢
║ 0 │ 0.4612               ║
╟───┼──────────────────────╢
║ 1 │ 0.5112               ║
╟───┼──────────────────────╢
║ 2 │ 0.6911               ║
╟───┼──────────────────────╢
║ 3 │ 0.4692               ║
╚═══╧══════════════════════╝
```

#### Selection by label

For getting a cross-section using a label:

```javascript
const dfd = require("danfojs")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
            "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]})
df.print()

let sub_df = df.loc({rows: ["a", "c"]})
sub_df.print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ a │ Apples            │ 21                │ 200               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ b │ Mango             │ 5                 │ 300               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ c │ Banana            │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ d │ Pear              │ 10                │ 250               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝


 Shape: (2,3) 

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ a │ Apples            │ 21                │ 200               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ c │ Banana            │ 30                │ 40                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Selecting on a multi-axis by label:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
            "Count": [21, 5, 30, 10],
             "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)
df.print()

let sub_df = df.loc({ rows: [0,1], columns: ["Name", "Price"] })
sub_df.print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ Apples            │ 21                │ 200               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 5                 │ 300               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ Banana            │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ Pear              │ 10                │ 250               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝


 Shape: (2,2) 

╔═══╤═══════════════════╤═══════════════════╗
║   │ Name              │ Price             ║
╟───┼───────────────────┼───────────────────╢
║ 0 │ Apples            │ 200               ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 300               ║
╚═══╧═══════════════════╧═══════════════════╝
```

Showing label slicing:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
            "Count": [21, 5, 30, 10],
             "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)
df.print()

let sub_df = df.loc({ rows: ["0:2"], columns: ["Name", "Price"] })
sub_df.print()
```

```
//before slicing
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ Apples            │ 21                │ 200               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 5                 │ 300               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ Banana            │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ Pear              │ 10                │ 250               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝

//after slicing
 

╔════════════╤═══════════════════╤═══════════════════╗
║            │ Name              │ Price             ║
╟────────────┼───────────────────┼───────────────────╢
║ 0          │ Apples            │ 200               ║
╟────────────┼───────────────────┼───────────────────╢
║ 1          │ Mango             │ 300               ║
╚════════════╧═══════════════════╧═══════════════════╝
```

#### Selection by position

Select via the position of the passed integers:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
           "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)

let sub_df = df.iloc({rows: [1,3]})
sub_df.print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 5                 │ 300               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ Pear              │ 10                │ 250               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
```

By integer slices:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
           "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)

let sub_df = df.iloc({rows: ["1:3"]})
sub_df.print()
```

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Name              │ Count             │ Price             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ Mango             │ 5                 │ 300               ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ Banana            │ 30                │ 40                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

By lists of integer position locations:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
           "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)

let sub_df = df.iloc({rows: [1,3], columns: [0,2]})
sub_df.print()
```

```
╔═══╤═══════════════════╤═══════════════════╗
║   │ Name              │ Price             ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 300               ║
╟───┼───────────────────┼───────────────────╢
║ 3 │ Pear              │ 250               ║
╚═══╧═══════════════════╧═══════════════════╝
```

For slicing rows explicitly:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
           "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)

let sub_df = df.iloc({rows: ["2:3"], columns: [":"]})
sub_df.print()
```

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Name              │ Count             │ Price             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ Banana            │ 30                │ 40                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

For slicing columns explicitly:

```javascript
const dfd = require("danfojs-node")

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
           "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data)

let sub_df = df.iloc({rows: [":"], columns: ["1:2"]})
sub_df.print()
```

```
╔════════════╤═══════════════════╗
║            │ Count             ║
╟────────────┼───────────────────╢
║ 0          │ 21                ║
╟────────────┼───────────────────╢
║ 1          │ 5                 ║
╟────────────┼───────────────────╢
║ 2          │ 30                ║
╟────────────┼───────────────────╢
║ 3          │ 10                ║
╚════════════╧═══════════════════╝
```

#### Selection with Boolean Mask

You can select subsections from a DataFrame by a booelan condition mask. E.g. In the following code, we select and return only rows where the column `Count` is greater than 10.

```javascript
let data = {
    "Name": ["Apples", "Mango", "Banana", "Pear"],
    "Count": [21, 5, 30, 10],
    "Price": [200, 300, 40, 250]
}

let df = new dfd.DataFrame(data)

let sub_df = df.iloc({ rows: df["Count"].gt(10) })
sub_df.print()
```

```
//output
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Name              │ Count             │ Price             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ Apples            │ 21                │ 200               ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ Banana            │ 30                │ 40                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

A Boolean mask for filtering also works for multiple conditions using `and` & `or` functions. E.g, In the following code, we select and return only rows where the column `Count` is greater than 10 and column `Name` is equal to `Apples`.

```javascript
let sub_df = df.iloc({
    rows: df["Count"].gt(10).and(df["Name"].eq("Apples")),
    columns: [0]
})
sub_df.print()

//output
╔════════════╤═══════════════════╗
║            │ Name              ║
╟────────────┼───────────────────╢
║ 0          │ Apples            ║
╚════════════╧═══════════════════╝
```

#### Boolean Querying/Filtering

The best way to query data is to use a boolean mask just as we demonstrated above with iloc and loc. For example, in the following code, we use a condition parameter to query the DataFrame:

```javascript
let data = {
    "A": ["Ng", "Yu", "Mo", "Ng"],
    "B": [34, 4, 5, 6],
    "C": [20, 20, 30, 40]
}
let df = new dfd.DataFrame(data)

let query_df = df.query(df["B"].gt(5))
query_df.print()
```

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ Ng                │ 34                │ 20                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ Ng                │ 6                 │ 40                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Querying by a boolean condition is supported from v0.3.0 and above. It also supports condition chaining as long as the final boolean mask is the same lenght as the DataFrame rows. For example in the following code, we use multiple chaining conditions:

```javascript
let data = {
    "A": ["Ng", "Yu", "Mo", "Ng"],
    "B": [34, 4, 5, 6],
    "C": [20, 20, 30, 40]
}
let query_df = df.query( df["B"].gt(5).and(df["C"].lt(0)))
query_df.print() //after query

//output
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ Ng                │ 34                │ 20                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

#### Adding a new column

Setting a new column automatically aligns the data by the indexes.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = { "A": [30, 1, 2, 3] ,
             "B": [34, 4, 5, 6] ,
             "C": [20, 20, 30, 40] }

let df = new dfd.DataFrame(data)
df.print()

let new_col = [1, 2, 3, 4]
df.addColumn("D", new_col, { inplace: true }); //happens inplace

df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>


        let data = { "A": [30, 1, 2, 3] ,
             "B": [34, 4, 5, 6] ,
             "C": [20, 20, 30, 40] }

        let df = new dfd.DataFrame(data)
        df.print()

        let new_col = [1, 2, 3, 4]
        df.addColumn({ "column": "D", "values": new_col, inplace: true }); //happens inplace

        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//before adding column
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 30                │ 34                │ 20                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 1                 │ 4                 │ 20                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 2                 │ 5                 │ 30                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 3                 │ 6                 │ 40                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝

//after adding column
 Shape: (4,3) 

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 │ D                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 30                │ 34                │ 20                │ 1                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 1                 │ 4                 │ 20                │ 2                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 2                 │ 5                 │ 30                │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 3                 │ 6                 │ 40                │ 4                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

### Missing data

**NaN, null,** and **undefined** represent missing data in Danfo.js. These values can be dropped or filled using some functions available in Danfo.js.

To drop any columns that have missing data:

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, 20, 78]]
let cols = ["A", "B", "C"]
let df = new dfd.DataFrame(data, { columns: cols })

df.print()

let df_drop = df.dropNa({ axis: 0 })
df_drop.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>


        let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]]
        let cols = ["A", "B", "C"]
        let df = new dfd.DataFrame(data, { columns: cols })

        df.print()

        let df_drop = df.dropNa({axis: 0})
        df_drop.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
//Before dropping
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1                 │ 2                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ NaN               │ 5                 │ 6                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ NaN               │ 30                │ 40                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 39                │ 20                │ 78                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


//after dropping
╔════════════╤═══════════════════╤═══════════════════╗
║            │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────╢
║ 0          │ 2                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────╢
║ 1          │ 5                 │ 6                 ║
╟────────────┼───────────────────┼───────────────────╢
║ 2          │ 30                │ 40                ║
╟────────────┼───────────────────┼───────────────────╢
║ 3          │ 20                │ 78                ║
╚════════════╧═══════════════════╧═══════════════════╝
```

To drop row(s) with have missing data, set the axis to 1:

```javascript
const dfd = require("danfojs-node")

let data = [[1, 2, 3], [NaN, 5, 6], [20, 30, 40], [39, 34, 78]]
let cols = ["A", "B", "C"]
let df = new dfd.DataFrame(data, { columns: cols })

df.print()

let df_drop = df.dropNa({ axis: 1 })
df_drop.print()
```

```
//Before dropping
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1                 │ 2                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ NaN               │ 5                 │ 6                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 20                │ 30               │ 40                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 39                │ 34                │ 78                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


//after dropping

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1                 │ 2                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 39                │ 20                │ 78                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Filling missing data:

```javascript
const dfd = require("danfojs-node")


let data = {
    "Name": ["Apples", "Mango", "Banana", NaN],
    "Count": [NaN, 5, NaN, 10],
    "Price": [200, 300, 40, 250]
  }

let df = new dfd.DataFrame(data)
let df_filled = df.fillNa("Apples")

df_filled.print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ Apples            │ Apples            │ 200               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 5                 │ 300               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ Banana            │ Apples            │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ Apples            │ 10                │ 250               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Filling missing values in specific columns with specific values:

```javascript
const dfd = require("danfojs-node")

let data = {
    "Name": ["Apples", "Mango", "Banana", NaN],
    "Count": [NaN, 5, NaN, 10],
    "Price": [200, 300, 40, 250]
}

let df = new dfd.DataFrame(data)
df.print()

let df_filled = df.fillNa(["Apples", df["Count"].mean()], { columns: ["Name", "Count"] })
df_filled.print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ Apples            │ 7.5               │ 200               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ Mango             │ 5                 │ 300               ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ Banana            │ 7.5               │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ Apples            │ 10                │ 250               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
```

To get the boolean mask where values are `nan`.

```javascript
const dfd = require("danfojs-node")

let data = {"Name":["Apples", "Mango", "Banana", undefined],
            "Count": [NaN, 5, NaN, 10], 
            "Price": [200, 300, 40, 250]}

let df = new dfd.DataFrame(data)
df.isNa().print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Name              │ Count             │ Price             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ false             │ true              │ false             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ false             │ false             │ false             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ false             │ true              │ false             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ true              │ false             │ false             ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
```

### Operations

#### Stats

Operations, in general, *exclude* missing data.

Performing a descriptive statistic:

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]]
cols = ["A", "B", "C"]


let df = new dfd.DataFrame(data, { columns: cols })
df.print()
df.mean().print() //defaults to column (1) axis
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script> 

    data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]]
    cols = ["A", "B", "C"]


    let df = new dfd.DataFrame(data)
    df.print()
    df.mean().print() //defaults to column axis

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 11                │ 20                │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 1                 │ 15                │ 6                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 2                 │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 2                 │ 89                │ 78                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝

╔═══╤════════════════════╗
║ 0 │ 11.333333333333334 ║
╟───┼────────────────────╢
║ 1 │ 7.333333333333333  ║
╟───┼────────────────────╢
║ 2 │ 24                 ║
╟───┼────────────────────╢
║ 3 │ 56.333333333333336 ║
╚═══╧════════════════════╝
```

Same operation on the row axis:

```javascript
const dfd = require("danfojs-node")

data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]]
cols = ["A", "B", "C"]


let df = new dfd.DataFrame(data)
df.print()
df.mean({ axis: 0 }).print() //row axis=0, column=1
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 11                │ 20                │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 1                 │ 15                │ 6                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 2                 │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 2                 │ 89                │ 78                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝

╔═══╤═══════╗
║ A │ 4     ║
╟───┼───────╢
║ B │ 38.5  ║
╟───┼───────╢
║ C │ 31.75 ║
╚═══╧═══════╝
```

Operations on objects with different dimensionality and need alignment. Danfo automatically broadcasts along the specified dimension.

```javascript
const dfd = require("danfojs-node")


let data = { "Col1": [1, 4, 5, 1], "Col2": [3, 2, 0, 4] }
let df = new dfd.DataFrame(data)
let sf = new dfd.Series([4, 5])

let df_new = df.sub(sf, { axis: 1 })

df_new.print()
```

```
╔═══╤═══════════════════╤═══════════════════╗
║   │ Col1              │ Col2              ║
╟───┼───────────────────┼───────────────────╢
║ 0 │ -3                │ -2                ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ 0                 │ -3                ║
╟───┼───────────────────┼───────────────────╢
║ 2 │ 1                 │ -5                ║
╟───┼───────────────────┼───────────────────╢
║ 3 │ -3                │ -1                ║
╚═══╧═══════════════════╧═══════════════════╝
```

#### Apply

Applying functions to the data along a specified axis. If axis = 1 (default), then the specified function (`callable)` will be called with each row data, and vice versa:

```javascript
const dfd = require("danfojs")

let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]]
let cols = ["A", "B", "C"]
let df = new dfd.DataFrame(data, { columns: cols })

function sum_vals(col) {
    return col.reduce((a, b) => a + b, 0);
}

let df_new = df.apply(sum_vals, { axis: 1 })
df_new.print()
```

```
//before applying
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 4                 │ 5                 │ 6                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 20                │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 39                │ 89                │ 78                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝


//after applying

╔═══╤═════╗
║ 0 │ 6   ║
╟───┼─────╢
║ 1 │ 15  ║
╟───┼─────╢
║ 2 │ 90  ║
╟───┼─────╢
║ 3 │ 206 ║
╚═══╧═════╝
```

Applying Element wise operations to the data:

You can use the `applyMap` function if you need to apply a function to each element in the DataFrame. `applyMap` works element-wise.

```javascript
const dfd = require("danfojs-node")

let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]]
let cols = ["A", "B", "C"]
let df = new dfd.DataFrame(data, { columns: cols })

function sum_vals(x) {
    return x + 10
}

let df_new = df.applyMap(sum_vals)
df_new.print()
```

```
//before applying
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 4                 │ 5                 │ 6                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 20                │ 30                │ 40                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 39                │ 89                │ 78                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝


 //after applyMap

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 11                │ 12                │ 13                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 14                │ 15                │ 16                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 30                │ 40                │ 50                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 49                │ 99                │ 88                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

#### String Methods

Series is equipped with a set of string processing methods in the **str** attribute that make it easy to operate on each element of the array, as in the code snippet below. Note that pattern-matching in **str** generally uses JavaScript [regular expressions](https://docs.python.org/3/library/re.html) by default (and in some cases always uses them).

```javascript
const dfd = require("danfojs-node")

let s = new dfd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA', 'dog', 'cat'])
let lower_s = s.str.toLowerCase()
lower_s.print()
```

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ a                    ║
╟───┼──────────────────────╢
║ 1 │ b                    ║
╟───┼──────────────────────╢
║ 2 │ c                    ║
╟───┼──────────────────────╢
║ 3 │ aaba                 ║
╟───┼──────────────────────╢
║ 4 │ baca                 ║
╟───┼──────────────────────╢
║ 5 │ caba                 ║
╟───┼──────────────────────╢
║ 6 │ dog                  ║
╟───┼──────────────────────╢
║ 7 │ cat                  ║
╚═══╧══════════════════════╝
```

See more string [accessors](https://jsdata.gitbook.io/danfojs/api-reference/series#accessors) here

### Merge

#### Concat

danfo provides various methods for easily combining together Series and DataFrame objects with various kinds of set logic for the indexes and relational algebra functionality in the case of join / merge-type operations.

Concatenating DataFrame together with [`concat()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.concat.html#pandas.concat):

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })


let com_df = dfd.concat({ dfList: [df1, df2], axis: 1 }) //along column axis
com_df.print()
```

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Key1              │ Key2              │ A                 │ B                 │ Key11             │ Key21             │ A1                │ D                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ K0                │ k0                │ A0                │ B0                │ K0                │ k0                │ C0                │ D0                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ k0                │ K1                │ A1                │ B1                │ K1                │ K0                │ C1                │ D1                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ K1                │ K0                │ A2                │ B2                │ K1                │ K0                │ C2                │ D2                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ K2                │ K2                │ A3                │ B3                │ K2                │ K0                │ C3                │ D3                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Concatenate along row axis (0).

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })


let com_df = dfd.concat({ dfList: [df1, df2], axis: 0 }) //along row axis
com_df.print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ K0                │ k0                │ C0                │ NaN               │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 5 │ K1                │ K0                │ C1                │ NaN               │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 6 │ K1                │ K0                │ C2                │ NaN               │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 7 │ K2                │ K0                │ C3                │ NaN               │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

#### Join

SQL style merges. See the Pandas [Database style joining](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#merging-join) section for more info.

```javascript
const dfd = require("danfojs-node")

let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
            ['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
            ['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })
df1.print()
df2.print()

let merge_df = dfd.merge({ "left": df1, "right": df2, "on": ["Key1"], how: "inner" })
merge_df.print()
```

```
 //first DataFrame
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //Second DataFrame

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //After inner join on column 'Key1'

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ Key2_1            │ A_1               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ A2                │ B2                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

See the [merge](https://jsdata.gitbook.io/danfojs/api-reference/general-functions/danfo.merge) section for more examples

### Grouping

By “group by” we are referring to a process involving one or more of the following steps:

> * **Splitting** the data into groups based on some criteria
> * **Applying** a function to each group independently
> * **Combining** the results into a data structure

See the [Grouping section](/api-reference/groupby).

```javascript
const dfd = require("danfojs-node")

let data ={'A': ['foo', 'bar', 'foo', 'bar',
                'foo', 'bar', 'foo', 'foo'],
           'B': ['one', 'one', 'two', 'three',
                'two', 'two', 'one', 'three'],
           'C': [1,3,2,4,5,2,6,7],
           'D': [3,2,4,1,5,6,7,8]
        }

let df = new dfd.DataFrame(data)


let grp = df.groupby(["A"])

grp.getGroup(["foo"]).print()

grp.getGroup(["bar"]).print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ foo               │ one               │ 1                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ foo               │ two               │ 2                 │ 4                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ foo               │ two               │ 5                 │ 5                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ foo               │ one               │ 6                 │ 7                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ foo               │ three             │ 7                 │ 8                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 Shape: (3,4) 

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ bar               │ one               │ 3                 │ 2                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ bar               │ three             │ 4                 │ 1                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ bar               │ two               │ 2                 │ 6                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

Grouping and then applying the[`sum()`](/api-reference/groupby/groupby.sum) function to the resulting groups.

```javascript
const dfd = require("danfojs-node")

let data = {
  A: ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
  B: ["one", "one", "two", "three", "two", "two", "one", "three"],
  C: [1, 3, 2, 4, 5, 2, 6, 7],
  D: [3, 2, 4, 1, 5, 6, 7, 8],
};

let df = new dfd.DataFrame(data);

let grp = df.groupby(["A"]);
grp.col(["C"]).sum().print();
```

```
╔═══╤═══════════════════╤═══════════════════╗
║   │ A                 │ C_sum             ║
╟───┼───────────────────┼───────────────────╢
║ 0 │ foo               │ 21                ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ bar               │ 9                 ║
╚═══╧═══════════════════╧═══════════════════╝
```

Grouping by multiple columns forms a hierarchical index, and again we can apply the[`sum()`](/api-reference/groupby/groupby.sum) function.

```javascript
const dfd = require("danfojs-node")

let data ={'A': ['foo', 'bar', 'foo', 'bar',
                'foo', 'bar', 'foo', 'foo'],
           'B': ['one', 'one', 'two', 'three',
                'two', 'two', 'one', 'three'],
           'C': [1,3,2,4,5,2,6,7],
           'D': [3,2,4,1,5,6,7,8]
        }

let df = new dfd.DataFrame(data)


let grp = df.groupby(["A","B"])
grp.col(["C"]).sum().print()
```

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C_sum             ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ foo               │ one               │ 7                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ foo               │ two               │ 7                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ foo               │ three             │ 7                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ bar               │ one               │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ bar               │ two               │ 2                 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 5 │ bar               │ three             │ 4                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
```

### Time series

danfo provides a simple but powerful, and efficient functionality for working with DateTime data. See the **dt** [Accessors](https://jsdata.gitbook.io/danfojs/api-reference/series#accessors) section.

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":'2018-01', freq:'M', period:3})
let sf = new dfd.Series(data)
//print series
sf.print()
//print month names
sf.dt.monthName().print()
```

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 1/1/2018, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 2/1/2018, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 2 │ 3/1/2018, 1:00:00 AM ║
╚═══╧══════════════════════╝

╔═══╤══════════╗
║ 0 │ January  ║
╟───┼──────────╢
║ 1 │ February ║
╟───┼──────────╢
║ 2 │ March    ║
╚═══╧══════════╝
```

More Examples:

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":'2018-01', freq:'M', period:3})
let sf = new dfd.Series(data)
//print series
sf.print()
//print week day names
sf.dt.dayOfWeekName().print()
```

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 1/1/2018, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 2/1/2018, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 2 │ 3/1/2018, 1:00:00 AM ║
╚═══╧══════════════════════╝

╔═══╤══════════╗
║ 0 │ Monday   ║
╟───┼──────────╢
║ 1 │ Thursday ║
╟───┼──────────╢
║ 2 │ Thursday ║
╚═══╧══════════╝
```

### Plotting

See the [Plotting](/api-reference/plotting) docs.

We currently support [Plotly.js](https://plotly.com/javascript/) for plotting. In the future, we plan other JS plotting libraries like Vega, D3.

Using the `plot` API, you can make interactive plots from DataFrame and Series. Plotting only works in the browser/client-side version of Danfo.js, and requires an HTML div to display plots.

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
     <title>Document</title>
</head>

<body>

    <div id="plot_div"></div>
    <script>

          dfd.readCSV(
          "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv"
        )
        .then((df) => {
          let layout = {
            title: "A financial charts",
            xaxis: {
              title: "Date",
            },
            yaxis: {
              title: "Count",
            },
          };

          let config = {
            columns: ["AAPL.Open", "AAPL.High"],
          };

          let new_df = df.setIndex({ column: "Date" });
          new_df.plot("plot_div").line({ config, layout });
        })
        .catch((err) => {
          console.log(err);
        });

    </script>
</body>

</html>
```

![](/files/N8sgXtuwF2HyQNupCKTY)

On a DataFrame, the [`plot()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html#pandas.DataFrame.plot)method exposes various [plot types](/api-reference/plotting). And by default, all columns are plotted unless specified otherwise.

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> 
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <div id="plot_div"></div>
    <script>

        df = new dfd.DataFrame({'pig': [20, 18, 489, 675, 1776],
                               'horse': [4, 25, 281, 600, 1900]}, {index: [1990, 1997, 2003, 2009, 2014]})
        df.plot("plot_div").line()

    </script>
</body>

</html>
```

![](/files/VA2dOnRIQv6b9cQQkm8e)

### Getting data in/out

#### CSV

[Writing to a CSV file.](/api-reference/dataframe/dataframe.to_csv)

Convert any DataFrame to csv format.

In NodeJs, if a file path is specified, then the CSV is saved to the path, else it is returned as a string.

In the browser, you can automatically download the file as CSV by setting the `download` paramater to `true`.

```javascript
const dfd = require("danfojs-node")
let data = {
    "Abs": [20.2, 30, 47.3],
    "Count": [34, 4, 5],
    "country code": ["NG", "FR", "GH"]
}


let df = new dfd.DataFrame(data)

const csv = dfd.toCSV(df)
console.log(csv);
//output
Abs,Count,country code
20.2,34,NG
30,4,FR
47.3,5,GH


dfd.toCSV(df, {filePath: "testOut.csv" }) //writes to file system in Nodejs


dfd.toCSV(df, {fileName: "testOut", download: true }) //downloads the file in browser version
```

```
Abs,Count,country code
20.2,34,NG
30,4,FR
47.3,5,GH
```

[Reading from a CSV file.](https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#io-read-csv-table)

The **readCSV** method can read CSV files from local disk, or over the internet. Both full and relative paths are supported. For example, to read a CSV file at the path **/home/Desktop/titanic.csv**, you can do the following:

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const dfd = require("danfojs")

dfd.readCSV("/home/Desktop/titanic.csv")
  .then(df => {

   //do something with the CSV file
   df.head().print()

  }).catch(err=>{
     console.log(err);
  })
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <script>

         dfd.readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
            .then(df => {

                //do something like display descriptive statistics
                df.describe().print()

            }).catch(err => {
                console.log(err);
            })

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

#### JSON

Writing to [JSON](/api-reference/dataframe/dataframe.to_json) format

```javascript
const dfd = require("danfojs-node")

let data = {
          "Abs": [20.2, 30, 47.3],
          "Count": [34, 4, 5],
          "country code": ["NG", "FR", "GH"]
        }


let df = new dfd.DataFrame(data)

const json = dfd.toJSON(df)
console.log(json);
//output
[
  { Abs: 20.2, Count: 34, 'country code': 'NG' },
  { Abs: 30, Count: 4, 'country code': 'FR' },
  { Abs: 47.3, Count: 5, 'country code': 'GH' }
]


const json = dfd.toJSON(df, {format: "row"})
console.log(json);
//output
{
  Abs: [ 20.2, 30, 47.3 ],
  Count: [ 34, 4, 5 ],
  'country code': [ 'NG', 'FR', 'GH' ]
}
```


# API reference

List of all public Danfo objects, functions and methods. All classes and functions exposed in danfo.\* namespace is public.

{% hint style="info" %}
A stable version of Danfojs (v1), has been released, and it comes with full Typescript support, new features, and many bug fixes. See release note [here](https://danfo.jsdata.org/pages/-MEmTsIPGMd_H6JAOlt9#latest-release-node-v1.0.0-browser-v1.0.0).

There are a couple of breaking changes, so we have prepared a short migration [guide](/examples/migrating-to-the-stable-version-of-danfo.js) for pre-v1 users.
{% endhint %}

* [General Functions](/api-reference/general-functions)
  * [Data manipulations](/api-reference/general-functions#data-manipulations)
  * [Data Processing/Normalization](/api-reference/general-functions#data-processing-normalization)
  * [Top-level dealing with datetime like](/api-reference/general-functions#top-level-dealing-with-datetime)
* [Input/output](/api-reference/input-output)
  * [CSV](/api-reference/input-output#csv)
  * [JSON](/api-reference/input-output#json)
* [Series](/api-reference/series)
  * [Attributes](/api-reference/series#attributes)
  * [Conversion](/api-reference/series#conversion)
  * [Indexing, iteration](/api-reference/series#indexing-iteration)
  * [Binary operator functions](/api-reference/series#binary-operator-functions)
  * [Function application, GroupBy & window](/api-reference/series#function-application-and-groupby)
  * [Computations / descriptive stats](/api-reference/series#computations-descriptive-stats)
  * [Reindexing / selection / label manipulation](/api-reference/series#reindexing-selection-label-manipulation)
  * [Missing data handling](/api-reference/series#missing-data-handling)
  * [Reshaping, sorting](/api-reference/series#reshaping-sorting)
  * [Accessors](/api-reference/series#accessors)
  * [Serialization / IO / conversion](/api-reference/series#serialization-io-conversion)
* [DataFrame](/api-reference/dataframe)
  * [Attributes](/api-reference/dataframe#attributes)
  * [Conversion](/api-reference/dataframe#conversion)
  * [Indexing, iteration](/api-reference/dataframe#indexing-iteration)
  * [Binary operator functions](/api-reference/dataframe#binary-operator-functions)
  * [Function application, GroupBy & window](/api-reference/dataframe#function-application-and-groupby)
  * [Computations / descriptive stats](/api-reference/dataframe#computations-descriptive-stats)
  * [Reindexing / selection / label manipulation](/api-reference/dataframe#reindexing-selection-label-manipulation)
  * [Missing data handling](/api-reference/dataframe#missing-data-handling)
  * [Reshaping, sorting, transposing](/api-reference/dataframe#sorting-and-transposing)
  * [Combining / comparing / joining / merging](/api-reference/dataframe#combining-comparing-joining-merging)
  * [Serialization / IO / conversion](/api-reference/dataframe#serialization-io-conversion)
* [Plotting](/api-reference/plotting)
  * [Line Charts](/api-reference/plotting/line-charts)
  * [Bar Charts](/api-reference/plotting/bar-charts)
  * [Scatter Plots](/api-reference/plotting/scatter-plots)
  * [Histograms](/api-reference/plotting/histograms)
  * [Pie Charts](/api-reference/plotting/pie-charts)
  * [Tables](/api-reference/plotting/tables)
  * [Box Plots](/api-reference/plotting/box-plots)
  * [Violin Plots](/api-reference/plotting/violin-plots)
  * [Timeseries Plots](/api-reference/plotting/timeseries-plots)
* [GroupBy](https://pandas.pydata.org/pandas-docs/stable/reference/groupby.html)
  * [Indexing, iteration](/api-reference/groupby#indexing-iteration)
  * [Function application](/api-reference/groupby#function-application)
  * [Computations / descriptive stats](/api-reference/groupby#computations-descriptive-stats)


# General Functions

Top level functions that can be called from the Danfo namespace

### Data transformation

|                                                                    |                                                                                                 |
| ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| [`merge`](/api-reference/general-functions/danfo.merge)            | Merge DataFrame or named Series objects with a database-style join.                             |
| [`concat`](/api-reference/general-functions/danfo.concat)          | Concatenate danfo objects along a particular axis with optional set logic along the other axes. |
| [`getDummies`](/api-reference/general-functions/danfo.get_dummies) | Convert categorical variable into dummy/indicator variables. Similar to OneHotEncoding          |

### Data Normalization

| [LabelEncoder](/api-reference/general-functions/danfo.labelencoder)     | Encode target labels with value between 0 and n\_classes-1.            |
| ----------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| [OneHotEncoder](/api-reference/general-functions/danfo.onehotencoder)   | Encode categorical features as a one-hot numeric array.                |
| [StandardScaler](/api-reference/general-functions/danfo.standardscaler) | Standardize features by removing the mean and scaling to unit variance |
| [`MinMaxScaler`](/api-reference/general-functions/danfo.minmaxscaler)   | Transform features by scaling each feature to a given range            |

### Working with DateTime

| [`toDateTime`](/api-reference/general-functions/danfo.to_datetime) | Convert argument to datetime.                                                                        |
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
| [`dateRange`](/api-reference/general-functions/danfo.date_range)   | Return a fixed frequency Datetime Index.                                                             |
| [Dt](/api-reference/general-functions/danfo.dt)                    | A class that converts strings of Date Time into a usable format, by exposing various helper methods. |

### Streaming Functions

| [streamCSV](/api-reference/general-functions/danfo.streamcsv)                                        | A function that loads a CSV object as a stream, returning intermediate rows as a DataFrame.             |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [streamJSON](/api-reference/general-functions/danfo.streamjson)                                      | A function that loads a JSON object as a stream, returning intermediate rows as a DataFrame.            |
| [streamCSVTransformer](/api-reference/general-functions/danfo.streamcsvtransformer)                  | A function that loads a CSV object as a stream, and applies a map-reduce function to intermediate rows. |
| [convertFunctionTotransformer](/api-reference/general-functions/danfo.-convertfunctiontotransformer) | A function to convert any JS function into a Stream transformer.                                        |

### Utility and Configurations

| [Utils](/api-reference/general-functions/danfo.utils)                                                                          | A utility class with helper methods mostly used internally. |
| ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
| [Config](https://github.com/javascriptdata/danfojs-doc/blob/master/api-reference/general-functions/broken-reference/README.md) | Base configuration class for NDframe objects                |

### Strings

| [Str](/api-reference/general-functions/danfo.str) | A class that converts strings into a usable format, by exposing various helper methods. |
| ------------------------------------------------- | --------------------------------------------------------------------------------------- |

### Internal Libs

| [tensoflow](/api-reference/general-functions/danfo.tensorflow) | Exported Tensorflow\.js library. This helps to avoid duplicated Tensorflow\.js library use. |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |


# danfo.tensorflow

Exported internal Tensoflow\.js library

danfo.**tensorflow**

**Returns:**

> return [Tensorflow.js](https://www.npmjs.com/package/@tensorflow/tfjs) library

## **Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
const tf = dfd.tensorflow

let tensor_arr = tf.tensor2d([[12, 34, 2.2, 2], [30, 30, 2.1, 7]])
console.log(tensor_arr)
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
    <script src="https://cdn.jsdelivr.net/gh/opensource9ja/danfojs@latest/lib/bundle.js"></script>
    <title>Document</title>
</head>

<body>

    <script>
        const tf = dfd.tensorflow
        let tensor_arr = tf.tensor2d([[12, 34, 2.2, 2], [30, 30, 2.1, 7]])
        console.log(tensor_arr)
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
Tensor {
  kept: false,
  isDisposedInternal: false,
  shape: [ 2, 4 ],
  dtype: 'float32',
  size: 8,
  strides: [ 4 ],
  dataId: {},
  id: 4,
  rankType: '2'
}
```

{% endtab %}
{% endtabs %}


# danfo. convertFunctionTotransformer

Converts a function to a pipe transformer. Only available in Nodejs version.

danfo.**convertFunctionTotransformer**(func)

| Parameters | Type     | Description                                                                                                                         | Default |
| ---------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------- |
| **func**   | Function | A valid JavaScript function to convert to a [pipe transformer.](https://nodejs.org/api/stream.html#implementing-a-transform-stream) |         |

**Returns:**

> return A [pipe transformer](https://nodejs.org/api/stream.html#implementing-a-transform-stream) that applies the function to each row of object.

The **convertFunctionTotransformer** takes a function and converts it to a Nodejs stream transformer function which can be used in combination with streamCsvTransformer to incrementally transform large files.

## **Converting a function to a transformer**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

/*
 * A simple function that takes each row of a DataFrame and splits the
 * name field. 
*/
const renamer = (dfRow: DataFrame) => {
    const dfModified = dfRow["Names"].map((name) => name.split(",")[0])
    return dfModified
}

const transformer = dfd.convertFunctionTotransformer(renamer)
console.log(transformer)
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
    <script src="https://cdn.jsdelivr.net/gh/opensource9ja/danfojs@latest/lib/bundle.js"></script>
    <title>Document</title>
</head>

<body>

    <script>

        let data = new dfd.date_range({"start":'1/1/2018',period:5, freq:'M'})
        console.log(data);
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
Transform {
  _readableState: ReadableState {
    objectMode: true,
    highWaterMark: 16,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    sync: false,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    destroyed: false,
    errored: null,
    closed: false,
    closeEmitted: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    writecb: null,
    writechunk: null,
    writeencoding: null
  }
}
```

{% endtab %}
{% endtabs %}


# danfo.streamCsvTransformer

A pipeline transformer to stream a CSV file from local storage, transform it with a custom transformer, and write to the output stream. Only available in Node.js

danfo.**streamCsvTransformer**(func)

| Parameters    | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| inputFilePath | Function | The path to the CSV file to stream from.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| transformer   | Function | <p>The transformer function to apply to each row.</p><p>Note that each row of the CSV file is passed as a DataFrame with a single row to the transformer function, and the transformer function is expected to return a transformed DataFrame.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| options       | object   | <p>Configuration options for the pipeline. These include:</p><ul><li><code>outputFilePath</code> The local file path to write the transformed CSV file to.</li><li><code>customCSVStreamWriter</code> A custom CSV stream writer function. This is applied at the end of each transform. If not provided, a default CSV stream writer is used, and this writes to local storage.</li><li><code>inputStreamOptions</code> Configuration options for the input stream. Supports all Papaparse CSV reader config options.</li><li><code>outputStreamOptions</code> Configuration options for the output stream. This is only applied when using the default CSV stream writer. Supports all <code>toCSV</code> options.</li></ul> |

**Returns:**

> A promise that resolves when the pipeline transformation is complete.

The streamCsvTransformer can be used to [incrementally transform](https://en.wikipedia.org/wiki/Stream_processing) a CSV file. This is done by:

* Streaming a CSV file from a local or **remote** path.
* Passing each corresponding row as a DataFrame to the specified transformer function.
* Writing the result to an output stream.

## **Stream processing a local file**

In the example below, we stream a local CSV file (titanic.csv), apply a transformer function, and write the output to **`titanicOutLocal.csv`**.

The transformer takes each `Name` column, splits the person's title, and creates a new column from it.

{% tabs %}
{% tab title="Node" %}

```javascript
import { DataFrame, Series, streamCsvTransformer } from "danfojs-node";
import path from "path"

const inputFilePath = path.join(process.cwd(), "raw_data", "titanic.csv");
const outputFilePath = path.join(process.cwd(), "raw_data", "titanicOutLocal.csv");

/**
 * A simple function that takes a DataFrame, and transforms the Name column.
* */
const transformer = (df) => {
    const titles = df["Name"].map((name) => name.split(".")[0]);
    const names = df["Name"].map((name) => name.split(".")[1]);
    df["Name"] = names
    df.addColumn("titles", titles, { inplace: true })
    return df
}

dfd.streamCsvTransformer(inputFilePath, transformer, {
    outputFilePath,
    inputStreamOptions: { header: false }
})
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//initial head of titanic.csv before transforming

PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2. 3101282,7.925,,S


//Head of titanicOutLocal.csv after transforming

PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked,titles
1,0,3, Owen Harris,male,22,1,0,A/5 21171,7.25,,S,Braund, Mr
2,1,1, John Bradley (Florence Briggs Thayer),female,38,1,0,PC 17599,71.2833,C85,C,Cumings, Mrs
3,1,3, Laina,female,26,0,0,STON/O2. 3101282,7.925,,S,Heikkinen, Miss
```

{% endtab %}
{% endtabs %}

## **Stream processing of remote file**

In the example below, we stream a remote CSV file (titanic.csv), applies a transformer function, and write the output to the `titanicOutLocal` file.

The transformer takes each `Name` column, splits the person's title, and creates a new column from it.

{% tabs %}
{% tab title="Node" %}

```javascript
import { DataFrame, Series, streamCsvTransformer } from "danfojs-node";
import path from "path"

const inputFilePath = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/titanic.csv"
const outputFilePath = path.join(process.cwd(), "raw_data", "titanicOutRemote.csv");


/**
 * A simple function that takes a DataFrame, and transforms the Name column.
* */
const transformer = (df) => {
    const titles = df["Name"].map((name) => name.split(".")[0]);
    const names = df["Name"].map((name) => name.split(".")[1]);
    df["Name"] = names
    df.addColumn("titles", titles, { inplace: true })
    return df
}

dfd.streamCsvTransformer(inputFilePath, transformer, {
    outputFilePath,
    inputStreamOptions: { header: false }
})
```

{% endtab %}
{% endtabs %}

## **Stream processing with a custom writer**

If you need custom control of the output writer, then you can provide a pipe-able custom writer. See <https://www.freecodecamp.org/news/node-js-streams-everything-you-need-to-know-c9141306be93/>

In the example below, we add a custom writer that logs each row. You can extend this to upload each chunk to a database, or any other function you need.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require('danfojs-node-nightly')
const path = require("path")
const stream = require("stream")

const inputFilePath = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/titanic.csv"

const transformer = (df) => {
    const titles = df["Name"].map((name) => name.split(".")[0]);
    const names = df["Name"].map((name) => name.split(".")[1]);
    df["Name"] = names
    df.addColumn("titles", titles, { inplace: true })
    return df
}
let count = 0

const customWriter = function () {
    const csvOutputStream = new stream.Writable({ objectMode: true })
    csvOutputStream._write = (chunk, encoding, callback) => {
        //Do anything here. For example you can write to online storage DB
        console.log("Chunk written: " + chunk) // Eah chunk is a row DataFrame
        count += 1
        callback()

    }
    return csvOutputStream
}

dfd.streamCsvTransformer(
    inputFilePath,
    transformer,
    {
        customCSVStreamWriter: customWriter,
        inputStreamOptions: { header: true }
    })
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//Showing the last log
...

Chunk written: 
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Survived          │ Pclass            │ Name              │ Sex               │ Age               │ Siblings/Spouse…  │ Parents/Childre…  │ Fare              │ titles            ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 884        │ 0                 │ 3                 │  Patrick Dooley   │ male              │ 32                │ 0                 │ 0                 │ 7.75              │ Mr                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}


# danfo.streamJSON

Streams a JSON file from a  local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.

danfo.**streamJSON**(filePath, callback, options)

| Parameters | Type     | Description                                                                                                                                                           |
| ---------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| filePath   | string   | URL or local file path to CSV file.                                                                                                                                   |
| callback   | Function | Callback function to be called once the specifed rows are parsed into DataFrame.                                                                                      |
| options    | object   | Optional configuration object. We use the `request` library for reading remote json files, Hence all `request` parameters such as `method`, `headers`, are supported. |

The **streamJSON** function streams a JSON file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.

## **Stream JSON file from local path**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
const path = require("path")

const filePath = path.join(process.cwd(), "raw_data", "book_small.json");

dfd.streamJSON(filePath, (df) => {
    if (df) {
        // Do any processing here
        df.print();
    }
});
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//Showing the last rows 
...

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ book_id           │ title             │ image_url         │ authors           ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 10         │ 32848471          │ Egomaniac         │ https://images.…  │ Vi Keeland        ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ book_id           │ title             │ image_url         │ authors           ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 11         │ 33288638          │ Wait for It       │ https://s.gr-as…  │ Mariana Zapata    ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

## **Stream JSON file from remote path**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
const path = require("path")

const remoteFile = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/book.json"

const callback = (df) => {
    //Perform any processing here
    if (df) {
        df.print();
    }
}

dfd.streamJSON(remoteFile, callback, { header: true })
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//Showing a few rows 
...

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ book_id           │ title             │ image_url         │ authors           ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 10         │ 32848471          │ Egomaniac         │ https://images.…  │ Vi Keeland        ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ book_id           │ title             │ image_url         │ authors           ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 11         │ 33288638          │ Wait for It       │ https://s.gr-as…  │ Mariana Zapata    ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}


# danfo.streamCSV

Streams a CSV file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.

danfo.**streamCSV**(filePath, callback, options)

| Parameters | Type     | Description                                                                                                    |
| ---------- | -------- | -------------------------------------------------------------------------------------------------------------- |
| filePath   | string   | URL or local file path to CSV file.                                                                            |
| callback   | Function | Callback function to be called once the specifed rows are parsed into DataFrame.                               |
| options    | object   | Optional configuration object. Supports all [Papaparse](https://www.papaparse.com/docs#config) config options. |

The **streamCSV** function streams a CSV file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.

## **Stream CSV file from local path**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
const path = require("path")

const filePath = path.join(process.cwd(), "raw_data", "titanic.csv");

dfd.streamCSV(filePath, (df) => {
    if (df) {
        // Do any processing here
        df.print();
    }
});
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//Showing few rows 
...

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ PassengerId       │ Survived          │ Pclass            │ Name              │ ...               │ Fare              │ Cabin             │ Embarked          ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 676        │ 687               │ 0                 │ 3                 │ Panula, Mr. Jaa…  │ ...               │ 39.6875           │                   │ S                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ PassengerId       │ Survived          │ Pclass            │ Name              │ ...               │ Fare              │ Cabin             │ Embarked          ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 677        │ 688               │ 0                 │ 3                 │ Dakic, Mr. Bran…  │ ...               │ 10.1708           │                   │ S                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

...
```

{% endtab %}
{% endtabs %}

## **Stream CSV file from remote path**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

const remoteFile = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/titanic.csv"

const callback = (df) => {
    //Perform any processing here
    if (df) {
        df.print();
    }
}

dfd.streamCSV(remoteFile, callback, { header: true })
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//Showing a few rows 
...

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Survived          │ Pclass            │ Name              │ Sex               │ Age               │ Siblings/Spouse…  │ Parents/Childre…  │ Fare              ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 523        │ 0                 │ 1                 │ Mr. John Farthi…  │ male              │ 49                │ 0                 │ 0                 │ 221.7792          ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ Survived          │ Pclass            │ Name              │ Sex               │ Age               │ Siblings/Spouse…  │ Parents/Childre…  │ Fare              ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 524        │ 0                 │ 3                 │ Mr. Johan Werne…  │ male              │ 39                │ 0                 │ 0                 │ 7.925             ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

...
```

{% endtab %}
{% endtabs %}


# danfo.Utils

Utility class with useful methods

The Utils class holds useful utility methods, mostly used internally in the Danfojs library.

For example, in the following example, we use the `inferDtype` function from the utils class.

{% tabs %}
{% tab title="Node" %}

```javascript
import { Utils } from "danfojs-node"

const utils = new Utils()

const arr = [NaN, 2.1, 3.3, 2.09]
console.log(utils.inferDtype(arr))

//output
[ 'float32' ]
```

{% endtab %}
{% endtabs %}


# danfo.Str

Accessor object for String-like properties of Series values.

For example, in the following example, we convert a Series to an `Str` instance and apply a couple of **String** methods.

{% tabs %}
{% tab title="Node" %}

```javascript
import { Str, Series } from "danfojs-node"

const sf = new Series(["Dog", "Cat", "Bird", "Fish", "ShArk", "tiGer"])
const sfStr = new Str(sf)

sfStr.toLowerCase().print()
sfStr.toUpperCase().print()
sfStr.join("Added", "-").print()
```

{% endtab %}
{% endtabs %}

```
// output
╔═══╤═══════╗
║ 0 │ dog   ║
╟───┼───────╢
║ 1 │ cat   ║
╟───┼───────╢
║ 2 │ bird  ║
╟───┼───────╢
║ 3 │ fish  ║
╟───┼───────╢
║ 4 │ shark ║
╟───┼───────╢
║ 5 │ tiger ║
╚═══╧═══════╝

╔═══╤═══════╗
║ 0 │ DOG   ║
╟───┼───────╢
║ 1 │ CAT   ║
╟───┼───────╢
║ 2 │ BIRD  ║
╟───┼───────╢
║ 3 │ FISH  ║
╟───┼───────╢
║ 4 │ SHARK ║
╟───┼───────╢
║ 5 │ TIGER ║
╚═══╧═══════╝
╔═══╤═════════════╗
║ 0 │ Dog-Added   ║
╟───┼─────────────╢
║ 1 │ Cat-Added   ║
╟───┼─────────────╢
║ 2 │ Bird-Added  ║
╟───┼─────────────╢
║ 3 │ Fish-Added  ║
╟───┼─────────────╢
║ 4 │ ShArk-Added ║
╟───┼─────────────╢
║ 5 │ tiGer-Added ║
╚═══╧═════════════╝
```


# danfo.Dt

Accessor object for date time properties of the Series values.

For example, in the following example, we convert a Series to an `Dt` instance and apply a couple of **DateTime** methods.

{% tabs %}
{% tab title="Node" %}

```javascript
import { Dt, Series } from "danfojs-node"

const sf = new Series(["1/1/2000", "1/2/2000", "2/3/2000", "1/4/2000", "4/5/2000"])
const dtS = new Dt(sf)

dtS.dayOfWeekName().print()
dtS.monthName().print()
```

{% endtab %}
{% endtabs %}

```
// output
╔═══╤═══════════╗
║ 0 │ Saturday  ║
╟───┼───────────╢
║ 1 │ Sunday    ║
╟───┼───────────╢
║ 2 │ Thursday  ║
╟───┼───────────╢
║ 3 │ Tuesday   ║
╟───┼───────────╢
║ 4 │ Wednesday ║
╚═══╧═══════════╝

╔═══╤══════════╗
║ 0 │ January  ║
╟───┼──────────╢
║ 1 │ January  ║
╟───┼──────────╢
║ 2 │ February ║
╟───┼──────────╢
║ 3 │ January  ║
╟───┼──────────╢
║ 4 │ April    ║
╚═══╧══════════╝
```


# danfo.dateRange

Return a fixed frequency Dates spread between start and end parameters.

danfo.**dateRange**(options)

| Parameters  | Type   | Description                                                                                                                                                                                                                                                                                                                                                             |
| ----------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **options** | Object | <p>Includes any of the following:</p><p><strong>start</strong>: Left bound for generating dates.</p><p><strong>end</strong>: Right bound for generating dates.</p><p><strong>period</strong> : Number of periods to generate.</p><p><strong>offSet</strong>: Date range offset</p><p><strong>freq</strong>: Date range frequency. One of \["M","D","s","H","m","Y"]</p> |

## **Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":'1/1/2018', period:5, freq:'M'})
console.log(data);
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
    <script src="https://cdn.jsdelivr.net/gh/opensource9ja/danfojs@latest/lib/bundle.js"></script>
    <title>Document</title>
</head>

<body>

    <script>

        let data = new dfd.date_range({"start":'1/1/2018',period:5, freq:'M'})
        console.log(data);
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
[
  '1/1/2018, 12:00:00 AM',
  '2/1/2018, 12:00:00 AM',
  '3/1/2018, 12:00:00 AM',
  '4/1/2018, 12:00:00 AM',
  '5/1/2018, 12:00:00 AM'
]
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({ "start": '1/1/2018', period: 12, freq: 'Y' })
console.log(data);
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
[
  '1/1/2018, 12:00:00 AM',
  '1/1/2019, 12:00:00 AM',
  '1/1/2020, 12:00:00 AM',
  '1/1/2021, 12:00:00 AM',
  '1/1/2022, 12:00:00 AM',
  '1/1/2023, 12:00:00 AM',
  '1/1/2024, 12:00:00 AM',
  '1/1/2025, 12:00:00 AM',
  '1/1/2026, 12:00:00 AM',
  '1/1/2027, 12:00:00 AM',
  '1/1/2028, 12:00:00 AM',
  '1/1/2029, 12:00:00 AM'
]
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Datetime properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the **dt** name space. See [Accessors](https://app.gitbook.com/@jsdata/s/danfojs/~/drafts/-MEMaWwva1cjt8CxnG-b/api-reference/series#accessors)
{% endhint %}


# danfo.OneHotEncoder

Encode categorical features as a one-hot numeric array.

class danfo.**OneHotEncoder**

danfo.js provides the OneHotEncoder class for encoding values in Series and Arrays to one-hot numeric arrays. This is mostly used as a preprocessing step before most machine learning tasks.

The API is similar to scikit-learn's [OneHotEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html?highlight=onehotencoder#sklearn.preprocessing.OneHotEncoder), and provides a fit and transform method.

## **Examples**

### **Convert Series to Dummy codes**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = {
    fruits: ['pear', 'mango', "pawpaw", "mango", "bean"],
    Count: [20, 30, 89, 12, 30],
    Country: ["NG", "NG", "GH", "RU", "RU"]
}


let df = new dfd.DataFrame(data)
let encode = new dfd.OneHotEncoder()

encode.fit(df['fruits'])
console.log(encode);

let sf_enc = encode.transform(df['fruits'].values)
console.log(sf_enc)

let new_sf = encode.transform(["mango", "bean"])
console.log(new_sf)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
OneHotEncoder { '$labels': [ 'pear', 'mango', 'pawpaw', 'bean' ] }
[
  [ 1, 0, 0, 0 ],
  [ 0, 1, 0, 0 ],
  [ 0, 0, 1, 0 ],
  [ 0, 1, 0, 0 ],
  [ 0, 0, 0, 1 ]
]
[ [ 0, 1, 0, 0 ], [ 0, 0, 0, 1 ] ]
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Labels not found in the original data used for fitting are represented with 0s all through**
{% endhint %}

See also [LabelEncoder](/api-reference/general-functions/danfo.labelencoder) and[ danfo.getDummies](/api-reference/general-functions/danfo.get_dummies)


# danfo.StandardScaler

Standardize features by removing the mean and scaling to unit variance.

class danfo.**StandScaler**

danfo.js provides the StandardScaler class for the standardization of DataFrame and Series. The standard score of a sample `x` is calculated as:

> z = (x - u) / s

where `u` is the mean of the training samples or zero if `with_mean=False`, and `s` is the standard deviation of the training samples or one if `with_std=False`.

The API is similar to sklearn's [StandardScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html?highlight=standardscaler#sklearn.preprocessing.StandardScaler), and provides a fit and transform method.

## **Examples**

### Standardize Series Object

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let scaler = new dfd.StandardScaler()

let sf = new dfd.Series([100,1000,2000, 3000])
sf.print()

scaler.fit(sf)

let sf_enc = scaler.transform(sf)
sf_enc.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════╗
║ 0 │ 100  ║
╟───┼──────╢
║ 1 │ 1000 ║
╟───┼──────╢
║ 2 │ 2000 ║
╟───┼──────╢
║ 3 │ 3000 ║
╚═══╧══════╝

╔═══╤═════════════════════╗
║ 0 │ -1.3135592937469482 ║
╟───┼─────────────────────╢
║ 1 │ -0.4839428961277008 ║
╟───┼─────────────────────╢
║ 2 │ 0.4378530979156494  ║
╟───┼─────────────────────╢
║ 3 │ 1.3596490621566772  ║
╚═══╧═════════════════════╝
```

{% endtab %}
{% endtabs %}

### Standardize DataFrame Object

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [[100, 1000, 2000, 3000],
        [20, 30, 89, 12],
        [1, 1, 1, 0]]

let df = new dfd.DataFrame(data, { columns: ['a', 'b', 'c', 'd'] })
df.print()

let scaler = new dfd.StandardScaler()
scaler.fit(df)

let df_enc = scaler.transform(df)
df_enc.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ a                 │ b                 │ c                 │ d                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 100               │ 1000              │ 2000              │ 3000              ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 20                │ 30                │ 89                │ 12                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 1                 │ 1                 │ 1                 │ 0                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ a                 │ b                 │ c                 │ d                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1.3909024000167…  │ 1.4137537479400…  │ 1.4131401777267…  │ 1.4142049551010…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ -0.473994612693…  │ -0.675643563270…  │ -0.658863127231…  │ -0.702851355075…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ -0.916907668113…  │ -0.738110065460…  │ -0.754277229309…  │ -0.711353600025…  ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

See also [MinMaxScaler](/api-reference/general-functions/danfo.minmaxscaler)


# danfo.MinMaxScaler

Transform features by scaling each feature to a range of max and min values.

class danfo.**MinMaxScaler**

danfo.js provides the MinMaxScaler class for standardization of DataFrame and Series. This estimator scales and translates each feature individually such that it is in the given range on the training set, e.g. between zero and one.

This transformation is often used as an alternative to zero mean, unit variance scaling like [Standardscaler](/api-reference/general-functions/danfo.standardscaler).

The API is similar to sklearn's [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html?highlight=minmaxscaler#sklearn.preprocessing.MinMaxScaler), and provides a fit and transform method.

## **Examples**

### Standardize DataFrame Object using MinMaxScaler

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let scaler = new dfd.MinMaxScaler()

let data = [[100,1000,2000, 3000] ,
            [20, 30, 20, 10],
            [1, 1, 1, 0]]

let df = new dfd.DataFrame(data)
df.print()

scaler.fit(df)

let df_enc = scaler.transform(df)
df_enc.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 100               │ 1000              │ 2000              │ 3000              ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 20                │ 30                │ 20                │ 10                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 1                 │ 1                 │ 1                 │ 0                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 Shape: (3,4) 

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ 0                 │ 1                 │ 2                 │ 3                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 1                 │ 1                 │ 1                 │ 1                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 0.19191919267...  │ 0.02902902849...  │ 0.00950475223...  │ 0.00333333341...  ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 0                 │ 0                 │ 0                 │ 0                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### Standardize Series Object Using MinMaxScaler

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
let scaler = new dfd.MinMaxScaler()

let data = [[100,1000,2000, 3000] ,
            [20, 30, 20, 10],
            [1, 1, 1, 0]]

let df = new dfd.DataFrame(data)
let sf = df.iloc({columns: [0]})

scaler.fit(sf)

let df_enc = scaler.transform(sf)
df_enc.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
 Shape: (3,1) 

╔═══╤═══════════════════╗
║   │ 0                 ║
╟───┼───────────────────╢
║ 0 │ 1                 ║
╟───┼───────────────────╢
║ 1 │ 0.19191919267...  ║
╟───┼───────────────────╢
║ 2 │ 0                 ║
╚═══╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

See also [MinMaxScaler](/api-reference/general-functions/danfo.minmaxscaler)


# danfo.LabelEncoder

Encode target labels with value between 0 and n\_classes-1.

class danfo.**LabelEncoder**

danfo.js provides the LabelEncoder class for encoding Series and Arrays to integer between 0 and n\_classes -1. This is mostly used as a preprocessing step before most machine learning tasks.

The API is similar to sklearn's [LabelEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html?highlight=labelencoder#sklearn.preprocessing.LabelEncoder), and provides a fit and transform method.

## **Examples**

### **Label Encode values in a Series**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require('danfojs-node')

let data = ["dog","cat","man","dog","cat","man","man","cat"]
let series = new dfd.Series(data)

let encode = new dfd.LabelEncoder()

encode.fit(series)
console.log(encode);

let sf_enc = encode.transform(series.values)
console.log(sf_enc)

let new_sf = encode.transform(["dog","man"])
console.log(new_sf)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
LabelEncoder { '$labels': { dog: 0, cat: 1, man: 2 } }
[
  0, 1, 2, 0,
  1, 2, 2, 1
]
[ 0, 2 ]
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Labels not found in the original data used for fitting are represented with -1**
{% endhint %}

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"] ,
            Count: [20, 30, 89, 12, 30],
            Country: ["NG", "NG", "GH", "RU", "RU"]}


let df = new dfd.DataFrame(data)
let encode = new dfd.LabelEncoder()

encode.fit(df['fruits'])
console.log(encode);

let sf_enc = encode.transform(df['fruits'].values)
console.log(sf_enc);

let new_sf = encode.transform(["mango","mane"])
console.log(new_sf);
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
LabelEncoder { '$labels': { pear: 0, mango: 1, pawpaw: 2, bean: 3 } }
[ 0, 1, 2, 1, 3 ]
[ 1, -1 ]
```

{% endtab %}
{% endtabs %}

See also [OneHotEncoder](/api-reference/general-functions/danfo.onehotencoder) and[ danfo.getDummies](/api-reference/general-functions/danfo.get_dummies)


# danfo.toDateTime

Converts an array of Date strings to Date object.

danfo.**toDateTime**(data)

| Parameters | Type          | Description     | Default                                           |
| ---------- | ------------- | --------------- | ------------------------------------------------- |
| **data**   | Array, Series | **data**: Array | Series with Date strings to convert to Date time. |

## **Examples**

In the following example, we convert a **Series** of Date strings to DateTime objects, so we can call various Date methods on them.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require('danfojs-node')

let data = new dateRange({ "start": '1/1/2018', period: 12, freq: 'M' })
let sf = new Series(data)
sf.print()

let dt = toDateTime(data)
dt.dayOfMonth().print()
dt.dayOfWeekName().print()
dt.hours().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════════════════════════╗
║ 0 │ 1/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 1 │ 2/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 2 │ 3/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 3 │ 4/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 4 │ 5/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 5 │ 6/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 6 │ 7/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 7 │ 8/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 8 │ 9/1/2018, 12:00:00 AM  ║
╟───┼────────────────────────╢
║ 9 │ 10/1/2018, 12:00:00 AM ║
╚═══╧════════════════════════╝

╔═══╤═══╗
║ 0 │ 1 ║
╟───┼───╢
║ 1 │ 1 ║
╟───┼───╢
║ 2 │ 1 ║
╟───┼───╢
║ 3 │ 1 ║
╟───┼───╢
║ 4 │ 1 ║
╟───┼───╢
║ 5 │ 1 ║
╟───┼───╢
║ 6 │ 1 ║
╟───┼───╢
║ 7 │ 1 ║
╟───┼───╢
║ 8 │ 1 ║
╟───┼───╢
║ 9 │ 1 ║
╚═══╧═══╝

╔═══╤═══════════╗
║ 0 │ Monday    ║
╟───┼───────────╢
║ 1 │ Thursday  ║
╟───┼───────────╢
║ 2 │ Thursday  ║
╟───┼───────────╢
║ 3 │ Sunday    ║
╟───┼───────────╢
║ 4 │ Tuesday   ║
╟───┼───────────╢
║ 5 │ Friday    ║
╟───┼───────────╢
║ 6 │ Sunday    ║
╟───┼───────────╢
║ 7 │ Wednesday ║
╟───┼───────────╢
║ 8 │ Saturday  ║
╟───┼───────────╢
║ 9 │ Monday    ║
╚═══╧═══════════╝

╔═══╤═══╗
║ 0 │ 0 ║
╟───┼───╢
║ 1 │ 0 ║
╟───┼───╢
║ 2 │ 0 ║
╟───┼───╢
║ 3 │ 0 ║
╟───┼───╢
║ 4 │ 0 ║
╟───┼───╢
║ 5 │ 0 ║
╟───┼───╢
║ 6 │ 0 ║
╟───┼───╢
║ 7 │ 0 ║
╟───┼───╢
║ 8 │ 0 ║
╟───┼───╢
║ 9 │ 0 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Date time properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the **dt** name-space. See [Accessors](https://app.gitbook.com/@jsdata/s/danfojs/~/drafts/-MEMaWwva1cjt8CxnG-b/api-reference/series#accessors)
{% endhint %}


# danfo.getDummies

Convert categorical variable into dummy/indicator variables.

danfo.**getDummies**(kwargs)

| Parameters  | Type                | Description                                                                                                                                                                                                                                                                                      | Default                                                      |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ |
| data        | Series or Dataframe | The data to dummify                                                                                                                                                                                                                                                                              |                                                              |
| **options** | Object              | <p>These includes:</p><p><strong>columns</strong>: Array of column names to dummify. If not specified, all categorical columns are encoded.</p><p><strong>prefixSeparator</strong>: String separator for created columns e.g "\_",</p><p><strong>prefix</strong>: Prefix for the new columns</p> | <p>{</p><p><strong>prefixSeparator</strong>: "-"</p><p>}</p> |

## **Examples**

### **Convert Series to Dummy codes**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let datasf = ['pear', 'mango', "pawpaw", "mango", "bean"]
let sf1 = new dfd.Series(datasf)

let dum_df = dfd.getDummies(sf1, { prefix: "fruit" })
dum_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ fruit_pear        │ fruit_mango       │ fruit_pawpaw      │ fruit_bean        ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1                 │ 0                 │ 0                 │ 0                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 0                 │ 1                 │ 0                 │ 0                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 0                 │ 0                 │ 1                 │ 0                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 0                 │ 1                 │ 0                 │ 0                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4          │ 0                 │ 0                 │ 0                 │ 1                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### **Convert all categorical columns in a DataFrame to Dummy codes**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"],
            Count: [20, 30, 89, 12, 30],
            Country: ["NG", "NG", "GH", "RU", "RU"]}

let df = new dfd.DataFrame(data)
df.print()

let dum_df = dfd.getDummies(df)
dum_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ fruits            │ Count             │ Country           ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ pear              │ 20                │ NG                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ mango             │ 30                │ NG                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ pawpaw            │ 89                │ GH                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ mango             │ 12                │ RU                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ bean              │ 30                │ RU                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝


 //after dummification

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Count             │ fruits_pear       │ fruits_mango      │ ...               │ fruits_bean       │ Country_NG        │ Country_GH        │ Country_RU        ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 20                │ 1                 │ 0                 │ ...               │ 0                 │ 1                 │ 0                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30                │ 0                 │ 1                 │ ...               │ 0                 │ 1                 │ 0                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 89                │ 0                 │ 0                 │ ...               │ 0                 │ 0                 │ 1                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 12                │ 0                 │ 1                 │ ...               │ 0                 │ 0                 │ 0                 │ 1                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ 30                │ 0                 │ 0                 │ ...               │ 1                 │ 0                 │ 0                 │ 1                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### **Convert a specific column in a DataFrame to Dummy codes**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"],
            Count: [20, 30, 89, 12, 30],
            Country: ["NG", "NG", "GH", "RU", "RU"]}

let df = new dfd.DataFrame(data)
df.print()

let dum_df = dfd.getDummies(df, { columns: ['fruits']})
dum_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ fruits            │ Count             │ Country           ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ pear              │ 20                │ NG                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ mango             │ 30                │ NG                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ pawpaw            │ 89                │ GH                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ mango             │ 12                │ RU                ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ bean              │ 30                │ RU                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝


 //after dummification

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Count             │ Country           │ fruits_pear       │ fruits_mango      │ fruits_pawpaw     │ fruits_bean       ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 20                │ NG                │ 1                 │ 0                 │ 0                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30                │ NG                │ 0                 │ 1                 │ 0                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 89                │ GH                │ 0                 │ 0                 │ 1                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 12                │ RU                │ 0                 │ 1                 │ 0                 │ 0                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ 30                │ RU                │ 0                 │ 0                 │ 0                 │ 1                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
See also [LabelEncoder](/api-reference/general-functions/danfo.labelencoder) and [OneHotEncoder](/api-reference/general-functions/danfo.onehotencoder)
{% endhint %}


# danfo.concat

Concatenate DataFrames and Series along an axis

danfo.**concat**(options)

| Parameters | Type   | Description                                                                                                                                                                                                                             | Default       |
| ---------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| options    | Object | <p>{</p><p><strong>dfList</strong>: List of DataFrames or Series to concatenate together.</p><p><strong>axis</strong>: One of 0 or 1. The axis on which to perform concatenation. Specified axis must align in both Objects</p><p>}</p> | {**axis**: 1} |

## **Examples**

### **Concatenate two DataFrames along column axis (1)**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })


let com_df = dfd.concat({ dfList: [df1, df2], axis: 1 })
com_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ ...               │ Key1_2            │ Key2_2            │ A_2               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ ...               │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ ...               │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ ...               │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ ...               │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### **Concatenate two DataFrames along row axis (0)**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })


let com_df = dfd.concat({ dfList: [df1, df2], axis: 0 })
com_df.print(10)
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ K0                │ k0                │ C0                │ NaN               │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 5 │ K1                │ K0                │ C1                │ NaN               │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 6 │ K1                │ K0                │ C2                │ NaN               │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 7 │ K2                │ K0                │ C3                │ NaN               │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### **Concatenate two Series along row axis (0)**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })


let com_df = dfd.concat({ dfList: [df1, df2], axis: 0 })
com_df.print(10)
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ K0                │ k0                │ C0                │ NaN               │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 5 │ K1                │ K0                │ C1                │ NaN               │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 6 │ K1                │ K0                │ C2                │ NaN               │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 7 │ K2                │ K0                │ C3                │ NaN               │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

See also [danfo.merge ](/api-reference/general-functions/danfo.merge)for joining objects based SQL-like joins.


# danfo.merge

Merge DataFrame or named Series objects with a database-style join.The join is done on columns or indexes.

danfo.**merge**(options)

| Parameters | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                            |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| options    | Object | <p><strong>left</strong>: A DataFrame or named Series object.</p><p><strong>right</strong>: Another DataFrame or named Series object.</p><p><strong>on</strong>: Column names to join on. Must be found in both the left and right DataFrame and/or Series objects.</p><p><strong>how</strong>: One of <code>'left','right'</code>,<code>'outer'</code>, <code>'inner'</code>. Defaults to 'inner'</p> |

## **Examples**

**danfo.js** merge function is similar to Pandas merge and performs in-memory join operations idiomatically very similar to relational databases like SQL.

danfo.js provides a single function, [`merge()`](/api-reference/general-functions/danfo.merge), as the entry point for all standard database join operations between `DataFrame` or named `Series` objects.

For a more intuitive understanding, this [guide](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#brief-primer-on-merge-methods-relational-algebra) on the [Pandas](https://pandas.pydata.org/pandas-docs/stable) doc is worth reading.

### **Merging by a single key found in both axis**

In the following example, we perform an inner join. An inner join requires each row in the two joined DataFrames to have matching column values. This is similar to the **intersection** of two sets. It returns a DataFrame with only those rows that have common characteristics.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
            ['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
            ['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })
df1.print()
df2.print()

let merge_df = dfd.merge({ "left": df1, "right": df2, "on": ["Key1"], how: "inner"})
merge_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
 //first DataFrame
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //Second DataFrame

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //After inner join on column 'Key1'

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ Key2_1            │ A_1               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ A2                │ B2                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### **Inner Join/Merge by multiple keys found in both axis**

Merging by two keys takes into consideration the keys appearing in both`left` and `right DataFrame.`

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
            ['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
            ['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })
df1.print()
df2.print()

let merge_df = dfd.merge({ left: df1, right: df2, 
                            on: ["Key1", 'Key2'], how: "inner"})
merge_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//first DataFrame
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


//second DataFrame

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //After inner join on two keys

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ A_1               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ A2                │ B2                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ C2                │ D2                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

The how parameter takes other types of joins like left, right and outer join and these are similar to their SQL equivalent

### Outer join/merge on DataFrame

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
            ['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
            ['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })
df1.print()
df2.print()

let merge_df = dfd.merge({ left: df1, right: df2, 
                            on: ["Key1"], how: "outer"})
merge_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//First DataFrame
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //Second DataFrame

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

//After outer join

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ Key2_1            │ A_1               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                │ NaN               │ NaN               │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K1                │ K0                │ A2                │ B2                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ K2                │ K2                │ A3                │ B3                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### Left join/merge on DataFrame

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
            ['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
            ['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })
df1.print()
df2.print()

let merge_df = dfd.merge({ left: df1, right: df2, 
                            on: ["Key1", "Key2"], how: "left"})
merge_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//first DataFrame
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


//second DataFrame

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 After left join
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ A_1               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                │ NaN               │ NaN               ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K1                │ K0                │ A2                │ B2                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ K2                │ K2                │ A3                │ B3                │ NaN               │ NaN               ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

### Right join/merge on DataFrame

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data = [['K0', 'k0', 'A0', 'B0'], ['k0', 'K1', 'A1', 'B1'],
            ['K1', 'K0', 'A2', 'B2'], ['K2', 'K2', 'A3', 'B3']]

let data2 = [['K0', 'k0', 'C0', 'D0'], ['K1', 'K0', 'C1', 'D1'],
            ['K1', 'K0', 'C2', 'D2'], ['K2', 'K0', 'C3', 'D3']]

let colum1 = ['Key1', 'Key2', 'A', 'B']
let colum2 = ['Key1', 'Key2', 'A', 'D']

let df1 = new dfd.DataFrame(data, { columns: colum1 })
let df2 = new dfd.DataFrame(data2, { columns: colum2 })
df1.print()
df2.print()

let merge_df = dfd.merge({ left: df1, right: df2, 
                            on: ["Key1", "Key2"], how: "right"})
merge_df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
//first DataFrame
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ k0                │ K1                │ A1                │ B1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K2                │ A3                │ B3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


 //second DataFrame

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝


//after right join

╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ Key1              │ Key2              │ A                 │ B                 │ A_1               │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ K0                │ k0                │ A0                │ B0                │ C0                │ D0                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ K1                │ K0                │ A2                │ B2                │ C1                │ D1                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ K1                │ K0                │ A2                │ B2                │ C2                │ D2                ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ K2                │ K0                │ NaN               │ NaN               │ C3                │ D3                ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
See also [danfo.concat ](/api-reference/general-functions/danfo.concat)for joining objects based on axis.
{% endhint %}


# Input/Output

Functions for reading tabular/structured data into DataFrame/Series Objects

## CSV

| \`\`                                                         |                                                          |
| ------------------------------------------------------------ | -------------------------------------------------------- |
| [`readCSV`](/api-reference/input-output/danfo.read_csv)      | Read a comma-separated values (csv) file into DataFrame. |
| [`read_excel`](/api-reference/input-output/danfo.read_excel) | Read an Excel values (xlsx) file into DataFrame.         |
| [`readJSON`](/api-reference/input-output/danfo.read_json)    | Read a JSON values (json) file into DataFrame.           |
| [toCSV](/api-reference/input-output/danfo.to_csv)            | Writes a DataFrame/Series to CSV file                    |
| [to\_excel](/api-reference/input-output/danfo.to_excel)      | Writes a DataFrame/Series to Excel file                  |
| [toJSON](/api-reference/input-output/danfo.to_json)          | Writes a DataFrame/Series to JSON file                   |

Writing to `CSV` and `JSON` can also be done directly from DataFrame or Series objects (e.g. [`DataFrame.toCSV()`](/api-reference/dataframe/dataframe.to_csv))


# danfo.readExcel

Reads a JSON file from local or remote location into a DataFrame.

> danfo.**readExcel**(source, options)

| Parameters | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| source     | string | **source** : string, URL or local file path to Excel file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| options    | Object | <p>{</p><p><strong>sheet</strong> : string, (Optional) Name of the sheet which u want to parse. Default will be the first sheet.<br><strong>method</strong>: The HTTP method to use.</p><p><strong>headers</strong>: Additional headers to send with the request if reading JSON from remote url. Supports all the node-fetch options in Nodejs, and all fetch options in browsers.</p><p><strong>frameConfig</strong>: Optional arguments passed when creating the DataFrame. e.g column names, index. etc.</p><p><strong>parsingOptions</strong>: supports all xlsx options. See <a href="https://docs.sheetjs.com/docs/api/parse-options"><https://docs.sheetjs.com/docs/api/parse-options></a></p><p>}</p> |

### Example

The **readExcel** method can read excel files saved on a local disk, or over the internet.

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")
const path = require("path")

let local_xcel = path.join(process.cwd(), "data", "testexcel.xlxs")

async function load_process_data() {
    let df = await dfd.readExcel(local_xcel)
    df.head().print()
}

load_process_data()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
     <title>Document</title>
</head>

<body>

    <script>

        const remote_url = 'https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_100.xls';
        dfd.readExcel(remote_url).then(df => {
            df.head().print()
        })

         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

### **Reading an input file object in the browser**

By specifying a valid [file object](https://developer.mozilla.org/en-US/docs/Web/API/File), you can load Excel files in the browser in DataFrames/Series

{% tabs %}
{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>
    <input type="file" id="file" name="file">
    <script>
        const inputFile = document.querySelector('#file')
        
        inputFile.addEventListener("change", async () => {
            const excelFile = inputFile.files[0]
            dfd.readExcel(excelFile).then((df) => {
                df.print()
            })
        })
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}


# danfo.toExcel

Converts a DataFrame or Series to Excel file, and write file to disk or download in browser.

> danfo.**toExcel**(data, options)

| **Parameters** | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Default                                                                                                  |
| -------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| ***data***     | Series or DataFrame | The Series or DataFrame to write to CSV                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                          |
| **options**    | object, optional    | <p>Configuration object:</p><p>{</p><p><strong><code>filePath</code></strong>: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version<br><strong><code>fileName</code></strong>: The name of the file to download as. Only needed in the browser environment.<br><strong><code>sheetName</code></strong>: Name to call the excel sheet.</p><p><strong>writingOptions</strong>: Supports all xlsx write options. See <a href="https://docs.sheetjs.com/docs/api/write-options"><https://docs.sheetjs.com/docs/api/write-options></a></p><p>}</p> | <p>{<br><strong>filePath</strong>: "./output.xlsx",<br><strong>sheetName</strong>: "Sheet1"<br><br>}</p> |

The **toExcel** function can be used to write out a DataFrame or Series to Excel (**.xlsx**) file. The output format will depend on the environment. In the following examples, we show you how to write/download an Excel file from Node and Browser environments.

### Convert DataFrame to Excel and write to file path

You can write a DataFrame or Series in Excel format using the toExcel function and specifying the file path.&#x20;

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

dfd.toExcel(df, { filePath: "testOut.xlsx"});
```

{% endtab %}
{% endtabs %}

### Convert DataFrame to Excel and download the file in Client-side lib

You can automatically convert and download an Excel file in a browser environment, by specifying a filename. This will open a download window.&#x20;

```javascript
let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new DataFrame(data);

dfd.toExcel(df, { fileName: "testOut.xlsx"});
```


# danfo.readJSON

Reads a JSON file into DataFrame.

> danfo.readJSON(source, options)

|                |                                                    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                                                 |
| -------------- | -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| **Parameters** | Type                                               | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Default                                         |
| ***source***   | Input file object, string file\*\* \*\*path or URL | <p>Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, https, ftp, s3, gs, or a local path. Both relative and absolute paths are supported</p><p>An input file object is also supported in the browser.</p>                                                                                                                                                                                                                    |                                                 |
| options        | Object                                             | <p>Configuration options for reading JSON files. Supported options:</p><p>{<br><code>method</code>: The HTTP method to use.</p><p><code>headers</code>: Additional headers to send with the request if reading JSON from remote url. Supports all the <a href="https://github.com/node-fetch/node-fetch#options">node-fetch options</a> in Nodejs, and all <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch options</a> in browsers.</p><p>}</p> | <p>{<br><strong>method</strong>: "GET"<br>}</p> |

The **readJSON** method can read JSON files from a local disk, over the internet, or directly from input file objects.

### **Reading JSON files from local disk**

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

dfd.readJSON("./user_names.json")
  .then(df => {
  
   df.head().print()

  }).catch(err=>{
     console.log(err);
  })
```

{% endtab %}
{% endtabs %}

### **Reading JSON files from a URL**

By specifying a valid URL, you can load JSON files from any location:

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

dfd.readJSON("https://raw.githubusercontentdatasets/master/finance-charts-apple.json") 
  .then(df => {
  
   df.head().print()

  }).catch(err=>{
     console.log(err);
  })
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <script>
     
     dfd.readJSON("https://raw.githubusercontentdatasets/master/finance-charts-apple.json") 
       .then(df => {
       
        df.head().print()
     
       }).catch(err=>{
          console.log(err);
       })
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

### **Reading an input file object in the browser**

By specifying a valid [file object](https://developer.mozilla.org/en-US/docs/Web/API/File), you can load a JSON file in the browser:

{% tabs %}
{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>
    <input type="file" id="file" name="file">
    <script>
            
        inputFile.addEventListener("change", async () => {
            const jsonFile = inputFile.files[0]
            dfd.readJSON(jsonFile).then((df) => {
                df.print()
            })
        })
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}


# danfo.toJSON

> danfo.toJSON(data, options)

|                |                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |                                                                 |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| **Parameters** | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Default                                                         |
| ***data***     | Series or DataFrame | The Series or DataFrame to write to CSV                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                 |
| **options**    | object, optional    | <p>Configuration object:</p><p>{</p><p><strong><code>filePath</code></strong>: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version<br><strong><code>fileName</code></strong>: The name of the file to download as. Only needed in browser environment.<br><strong><code>format</code></strong>: The format of the JSON. Can be one of <strong><code>row</code></strong> or <strong><code>column</code></strong>.</p><p>}</p> | <p>{<br><strong><code>format</code></strong>: "column"<br>}</p> |

The **toJSON** function can be used to write out a DataFrame or Series to JSON format/file. The output is configurable and will depend on the environment. In the following examples, we show you how to write/download a JSON file from Node and Browser environments.

### Convert DataFrame/Series to JSON and return value

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

let data = {
  Abs: [20.2, 30, 47.3],
  Count: [34, 4, 5],
  "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

const jsonObj = dfd.toJSON(df); //column format
console.log(jsonObj);

//output
[
  { Abs: 20.2, Count: 34, 'country code': 'NG' },
  { Abs: 30, Count: 4, 'country code': 'FR' },
  { Abs: 47.3, Count: 5, 'country code': 'GH' }
]

//row format
const jsonObj = dfd.toJSON(df, {
    format: "row"
});

console.log(jsonObj);
//output
{
  Abs: [ 20.2, 30, 47.3 ],
  Count: [ 34, 4, 5 ],
  'country code': [ 'NG', 'FR', 'GH' ]
}
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <script>

       let data = {
          Abs: [20.2, 30, 47.3],
          Count: [34, 4, 5],
          "country code": ["NG", "FR", "GH"],
        };
        
        let df = new dfd.DataFrame(data);
        
        const csv = df.toJSON();
        console.log(csv);
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

### Convert DataFrame/Series to JSON and write to file path

Writing a DataFrame/Series as JSON, to a local file path is only supported in the Nodejs environment

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

dfd.toJSON(df, { filePath: "./testOutput.json" });
```

{% endtab %}
{% endtabs %}

### Convert DataFrame/Series to JSON and download file in browser

You can automatically convert and download a DataFrame/Series as a JSON file in a browser environment, by specifying a `fileName` and setting `download` to **true**.

```javascript
let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

dfd.toJSON(df, { fileName: "test_out.json", download: true });
```


# danfo.readCSV

Reads a comma-separated values (CSV) file into DataFrame. Also supports the reading of CSV files in chunks.

> danfo.**readCSV**(source, options)

|                |                             |                                                                                                                                                                                                                            |                                                                       |
| -------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| **Parameters** | Type                        | Description                                                                                                                                                                                                                | Default                                                               |
| ***source***   | File object, File path, URL | <p>Any valid string path is acceptable. The string could be a URL or a valid local file path.</p><p>A browser <a href="https://developer.mozilla.org/en-US/docs/Web/API/File">input file object</a> is also supported.</p> |                                                                       |
| **options**    | object, optional            | Supports all Papaparse config parameters. See <https://www.papaparse.com/docs#config>.                                                                                                                                     | <p><strong>{</strong></p><p><strong>header:</strong> true</p><p>}</p> |

The **readCSV** method can read a CSV file from a local disk, or over the internet (URL). Reading of local files is only supported in Nodejs, while reading of input file objects is only supported in the browser.

### **Reading files from local disk**

By specifying a valid file path, you can load CSV files from local disk:

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

dfd.readCSV("./user_names.csv") //assumes file is in CWD
  .then(df => {
  
   df.head().print()

  }).catch(err=>{
     console.log(err);
  })
```

{% endtab %}
{% endtabs %}

### **Reading files from a URL**

By specifying a valid URL, you can load CSV files from any location into Danfo\*\*'\*\*s data structure:

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

dfd.readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") //assumes file is in CWD
  .then(df => {
  
   df.head().print()

  }).catch(err=>{
     console.log(err);
  })
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.plot.ly/plotly-2.2.0.min.js"></script> 
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <div id="plot_div"></div>
    <script>

         dfd.readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
            .then(df => {

                //do something like display descriptive statistics
                df.describe().print()
                
            }).catch(err => {
                console.log(err);
            })
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

### **Reading an input file object in the browser**

By specifying a valid [file object](https://developer.mozilla.org/en-US/docs/Web/API/File), you can load CSV files in the browser in DataFrames/Series

{% tabs %}
{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>
    <input type="file" id="file" name="file">
    <script>
            
        inputFile.addEventListener("change", async () => {
            const csvFile = inputFile.files[0]
            dfd.readCSV(csvFile).then((df) => {
                df.print()
            })
        })
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}


# danfo.toCSV

Writes a DataFrame or Series to CSV format.

> danfo.**toCSV**(data, options)

|                |                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |                                                                                     |
| -------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| **Parameters** | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Default                                                                             |
| ***data***     | Series or DataFrame | The Series or DataFrame to write to CSV                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                     |
| **options**    | object, optional    | <p>Configuration object:</p><p>{</p><p><strong><code>filePath</code></strong>: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version<br><strong><code>fileName</code></strong>: The name of the file to download as. Only needed in browser environment.<br><strong><code>download</code></strong>: Boolean indicating whether to automatically download the CSV file in the browser. Only needed in the browser environment.</p><p><strong><code>header</code></strong>: Boolean indicating whether to include a header row in the CSV file.</p><p><strong><code>sep</code></strong>: Character to be used as a separator in the CSV file.</p><p>}</p> | <p>{<br><strong>download</strong>: false,<br><strong>sep</strong>: ","<br><br>}</p> |

The **toCSV** function can be used to write out a DataFrame or Series to CSV file. The output is configurable and will depend on the environment. In the following examples, we show you how to write/download a CSV file from Node and Browser environments.

### Convert DataFrame to CSV string and return value

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

let data = {
  Abs: [20.2, 30, 47.3],
  Count: [34, 4, 5],
  "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

const csv = dfd.toCSV(df);
console.log(csv);

//output
Abs,Count,country code
20.2,34,NG
30,4,FR
47.3,5,GH
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <script>

       let data = {
          Abs: [20.2, 30, 47.3],
          Count: [34, 4, 5],
          "country code": ["NG", "FR", "GH"],
        };
        
        let df = new dfd.DataFrame(data);
        
        const csv = df.toCSV();
        console.log(csv);
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

### Convert DataFrame to CSV string and write to file path

Writing a CSV file to a local file path is only supported in the Nodejs environment

{% tabs %}
{% tab title="Node.js" %}

```javascript
const dfd = require("danfojs-node")

let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

dfd.toCSV(df, { filePath: "testOut.csv"});
```

{% endtab %}
{% endtabs %}

### Convert DataFrame to CSV string and download file in Client-side lib

You can automatically convert and download a CSV file in a browser environment, by specifying a `fileName` and setting `download` to **true**.

```javascript
const dfd = require("danfojs")

let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

dfd.toCSV(df, { fileName: "testOut.csv", download: true});
```


# Series

One-dimensional ndarray with axis labels (including time series).

> `Series`(data, {**columns:** \[ Array ], **dtypes:** \[ Array ], **index:** \[Array]}) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/series.js#L28)]

### Attributes

| [`Series.index`](/api-reference/series/series.index) | The index (axis labels) of the Series. |
| ---------------------------------------------------- | -------------------------------------- |

| [`Series.tensor`](/api-reference/series/series.tensor)                                                                     | The Tensorflow tensor of the data backing this Series or Index.  |
| -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [`Series.values`](/api-reference/series/series.values)                                                                     | Return Series as ndarray or ndarray-like depending on the dtype. |
| [`Series.dtype`](/api-reference/series/series.dtype)                                                                       | Return the dtype object of the underlying data.                  |
| [`Series.shape`](/api-reference/series/series.shape)                                                                       | Return a tuple of the shape of the underlying data.              |
| [`Series.ndim`](/api-reference/series/series.ndim)                                                                         | Number of dimensions of the underlying data, by definition 1.    |
| [`Series.size`](https://github.com/javascriptdata/danfojs-doc/blob/master/api-reference/series/broken-reference/README.md) | Return the number of elements in the underlying data.            |

### Conversion

| [`Series.asType`](/api-reference/dataframe/dataframe.astype) | Cast a Series object to a specified dtype      |
| ------------------------------------------------------------ | ---------------------------------------------- |
| [`Series.copy`](/api-reference/series/series.copy)           | Make a copy of this object’s indices and data. |

### Indexing, iteration

|                                                    |                                                                    |
| -------------------------------------------------- | ------------------------------------------------------------------ |
| ``[`Series.loc`](series.loc.md)``                  | Access a group of rows and columns by label(s) or a boolean array. |
| [`Series.iloc`](/api-reference/series/series.iloc) | Purely integer-location based indexing for selection by position.  |

### Binary operator functions

| [`Series.add`](/api-reference/series/series.add)     | Return Addition of series and other, element-wise (binary operator add).                |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------- |
| [`Series.sub`](/api-reference/series/series.sub)     | Return Subtraction of series and other, element-wise (binary operator sub).             |
| [`Series.mul`](/api-reference/series/series.mul)     | Return Multiplication of series and other, element-wise (binary operator mul).          |
| [`Series.div`](/api-reference/series/series.div)     | Return Floating division of series and other, element-wise (binary operator truediv).   |
| [`Series.mod`](/api-reference/series/series.mod)     | Return Modulo of series and other, element-wise (binary operator mod).                  |
| [`Series.pow`](/api-reference/series/series.pow)     | Return Exponential power of series and other, element-wise (binary operator pow).       |
| [`Series.round`](/api-reference/series/series.round) | Round each value in a Series to the given number of decimals.                           |
| [`Series.lt`](/api-reference/series/series.lt)       | Return Less than of series and other, element-wise (binary operator lt).                |
| [`Series.gt`](/api-reference/series/series.gt)       | Return Greater than of series and other, element-wise (binary operator gt).             |
| [`Series.le`](/api-reference/series/series.le)       | Return Less than or equal to of series and other, element-wise (binary operator le).    |
| [`Series.ge`](/api-reference/series/series.ge)       | Return Greater than or equal to of series and other, element-wise (binary operator ge). |
| [`Series.ne`](/api-reference/series/series.ne)       | Return Not equal to of series and other, element-wise (binary operator ne).             |
| [`Series.eq`](/api-reference/series/series.eq)       | Return Equal to of series and other, element-wise (binary operator eq).                 |

### Function application

| [`Series.apply`](/api-reference/series/series.apply) | Invoke function on values of Series.                    |
| ---------------------------------------------------- | ------------------------------------------------------- |
| [`Series.map`](/api-reference/series/series.map)     | Map values of Series according to input correspondence. |

### Computations / descriptive stats

| [`Series.abs`](/api-reference/series/series.abs)                                                                           | Return a Series with absolute numeric value of each element.     |
| -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [`Series.corr`](https://github.com/javascriptdata/danfojs-doc/blob/master/api-reference/series/broken-reference/README.md) | Compute correlation with other Series, excluding missing values. |
| [`Series.count`](/api-reference/series/series.count)                                                                       | Return number of non-NaN observations in the Series.             |
| [`Series.cumMax`](/api-reference/dataframe/danfo.dataframe.cummax)                                                         | Return cumulative maximum over a DataFrame or Series axis.       |
| [`Series.cumMin`](/api-reference/dataframe/danfo.dataframe.cummin)                                                         | Return cumulative minimum over a DataFrame or Series axis.       |
| [`Series.cumProd`](/api-reference/dataframe/danfo.dataframe.cumprod)                                                       | Return cumulative product over a DataFrame or Series axis.       |
| [`Series.cumSum`](/api-reference/dataframe/danfo.dataframe.cumsum)                                                         | Return cumulative sum over a DataFrame or Series axis.           |
| [`Series.describe`](/api-reference/series/series.describe)                                                                 | Generate descriptive statistics.                                 |
| [`Series.max`](/api-reference/series/series.max)                                                                           | Return the maximum of the values for the requested axis.         |
| [`Series.mean`](/api-reference/series/series.mean)                                                                         | Return the mean of the values for the requested axis.            |
| [`Series.median`](/api-reference/series/series.median)                                                                     | Return the median of the values for the requested axis.          |
| [`Series.min`](/api-reference/series/series.min)                                                                           | Return the minimum of the values for the requested axis.         |
| [`Series.mode`](/api-reference/series/series.mode)                                                                         | Return the mode(s) of the dataset.                               |
| [`Series.std`](/api-reference/series/series.std)                                                                           | Return sample standard deviation over requested axis.            |
| [`Series.sum`](/api-reference/series/series.sum)                                                                           | Return the sum of the values for the requested axis.             |
| [`Series.var`](/api-reference/series/series.var)                                                                           | Return unbiased variance over requested axis.                    |
| [`Series.unique`](/api-reference/series/series.unique)                                                                     | Return unique values of Series object.                           |
| [`Series.nUnique`](/api-reference/series/series.nunique)                                                                   | Return number of unique elements in the object.                  |
| [`Series.valueCounts`](/api-reference/series/series.value_counts)                                                          | Return a Series containing counts of unique values.              |

### Reindexing / selection / label manipulation

|                                                                         |                                                          |
| ----------------------------------------------------------------------- | -------------------------------------------------------- |
| [`Series.dropDuplicates`](/api-reference/series/series.drop_duplicates) | Return Series with duplicate values removed.             |
| [`Series.head`](/api-reference/series/series.head)                      | Return the first n rows.                                 |
| [`Series.resetIndex`](/api-reference/series/series.reset_index)         | Generate a new DataFrame or Series with the index reset. |
| [`Series.sample`](/api-reference/series/series.sample)                  | Return a random sample of items from an axis of object.  |
| [`Series.tail`](/api-reference/series/series.tail)                      | Return the last n rows.                                  |

### Missing data handling

|                                                          |                                                  |
| -------------------------------------------------------- | ------------------------------------------------ |
| [`Series.droNa`](/api-reference/series/series.dropna)    | Return a new Series with missing values removed. |
| [`Series.fillNa`](/api-reference/series/series.fillna)   | Fill NaN values using the specified method.      |
| [`Series.isNa`](/api-reference/series/series.isna)       | Detect missing values.                           |
| [`Series.replace`](/api-reference/series/series.replace) | Replace values given in to\_replace with value.  |

### Logical Comparison

|                                                  |                                                                                                      |
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
| [`Series.or`](/api-reference/series/series.or)   | Returns the logical OR between Series and other. Supports element-wise operations and broadcasting.  |
| [`Series.and`](/api-reference/series/series.and) | Returns the logical AND between Series and other. Supports element-wise operations and broadcasting. |

### Reshaping, sorting

| [`Series.argSort`](/api-reference/series/series.argsort)        | Return the integer indices that would sort the Series values. |
| --------------------------------------------------------------- | ------------------------------------------------------------- |
| [`Series.argMin`](/api-reference/series/series.argmin)          | Return int position of the smallest value in the Series.      |
| [`Series.argMax`](/api-reference/series/series.argmax)          | Return int position of the largest value in the Series.       |
| [`Series.sortValues`](/api-reference/series/series.sort_values) | Sort by the values.                                           |

### Accessors

Danfo provides dtype-specific methods under various accessors. These are separate namespaces within [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) that only apply to specific data types.

| Data Type                                             | Accessor |
| ----------------------------------------------------- | -------- |
| [Datetime](/api-reference/general-functions/danfo.dt) | dt       |
| [String](/api-reference/general-functions/danfo.str)  | str      |

#### Datetimelike properties

`Series.dt` can be used to access the values of the series as datetime and return several properties. These can be accessed like `Series.dt.<property>`.

**Datetime methods**

|                                                                       |                                                                         |
| --------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [`Series.dt.year`](/api-reference/series/series.dt.year)              | The year of the datetime.                                               |
| [`Series.dt.month`](/api-reference/series/series.dt.month)            | Returns a numeric representation of the month. January=0 - December=11. |
| [Series.dt.monthName](/api-reference/series/series.dt.month_name)     |                                                                         |
| [`Series.dt.dayOfWeek`](/api-reference/series/series.dt.day)          | Returns the day of the week, in local time                              |
| [`Series.dt.hour`](/api-reference/series/series.dt.hour)              | The hours of the datetime.                                              |
| [`Series.dt.minute`](/api-reference/series/series.dt.minute)          | The minutes of the datetime.                                            |
| [`Series.dt.second`](/api-reference/series/series.dt.second)          | The seconds of the datetime.                                            |
| [`Series.dt.dayOfWeekName`](/api-reference/series/series.dt.weekdays) | Returns the name of the day, of the week, in local time                 |
| [`Series.dt.dayOfMonth`](/api-reference/series/series.dt.month_name)  | Returns the day of the month, in local time                             |

#### String handling

`Series.str` can be used to access the values of the series as strings and apply several methods to it. These can be accessed like `Series.str.<function/property>`.

| [`Series.str.capitalize`](/api-reference/series/series.str.capitalize)   | Capitalize the first character of each string                                                                                  |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| [`Series.str.toUpperCase`](/api-reference/series/series.str.touppercase) | Converts all characters to uppercase.                                                                                          |
| [`Series.str.toLowerCase`](/api-reference/series/series.str.tolowercase) | Converts all characters to lowercase.                                                                                          |
| [`Series.str.charAt`](/api-reference/series/series.str.charat)           | Returns the character at the specified index (position).                                                                       |
| [`Series.str.concat`](/api-reference/series/series.str.concat)           | Joins two or more strings/arrays.                                                                                              |
| [`Series.str.startsWith`](/api-reference/series/series.str.startswith)   | Checks whether a string begins with specified characters.                                                                      |
| [`Series.str.endsWith`](/api-reference/series/series.str.endswith)       | Checks whether a string ends with specified characters                                                                         |
| [`Series.str.includes`](/api-reference/series/series.str.includes)       | Checks whether a string contains the specified string/characters.                                                              |
| [`Series.str.indexOf`](/api-reference/series/series.str.indexof)         | Returns the position of the first found occurrence of a specified value in a string.                                           |
| [`Series.str.lastIndexOf`](/api-reference/series/series.str.lastindexof) | Returns the position of the last found occurrence of a specified value in a string.                                            |
| [`Series.str.repeat`](/api-reference/series/series.str.repeat)           | Returns a new string with a specified number of copies of an existing string.                                                  |
| [`Series.str.search`](/api-reference/series/series.str.search)           | Searches a string for a specified value, or regular expression, and returns the position of the match.                         |
| [`Series.str.slice`](/api-reference/series/series.str.slice)             | Extracts a part of a string and returns a new string.                                                                          |
| [`Series.str.split`](/api-reference/series/series.str.split)             | Splits a string into an array of substrings.                                                                                   |
| [`Series.str.substr`](/api-reference/series/series.str.substr)           | Extracts the characters from a string, beginning at a specified start position, and through the specified number of character. |
| [`Series.str.substring`](/api-reference/series/series.str.substring)     | Extracts the characters from a string, between two specified indices.                                                          |
| [`Series.str.len`](/api-reference/series/series.str.len)                 | Counts the number of characters in each string.                                                                                |
| [`Series.str.trim`](/api-reference/series/series.str.trim)               | Removes whitespace from both ends of a string.                                                                                 |
| [`Series.str.join`](/api-reference/series/series.str.join)               | Joins strings to specified value.                                                                                              |
| [`Series.str.replace`](/api-reference/series/series.str.replace)         | Replace each occurrence of pattern/regex in the Series/Index.                                                                  |

### Plotting

`Series.plot` is both a callable method and a namespace attribute for specific plotting methods of the form `Series.plot.<kind>`.

|                                                                |                                                               |
| -------------------------------------------------------------- | ------------------------------------------------------------- |
| [`Series.plot.bar`](/api-reference/plotting/bar-charts)        | Vertical bar plot.                                            |
| [`Series.plot.box`](/api-reference/plotting/box-plots)         | Make a box plot of the DataFrame columns.                     |
| [`Series.plot.violin`](/api-reference/plotting/box-plots)      | Make a violin plot of the DataFrame columns.                  |
| [`Series.plot.hist`](/api-reference/plotting/histograms)       | Draw one histogram of the DataFrame’s columns.                |
| [`Series.plot.scatter`](/api-reference/plotting/scatter-plots) | Generate Kernel Density Estimate plot using Gaussian kernels. |
| [`Series.plot.line`](/api-reference/plotting/line-charts)      | Plot Series or DataFrame as lines.                            |
| [`Series.plot.pie`](/api-reference/plotting/pie-charts)        | Generate a pie plot.                                          |
| [`Timeseries Plots`](/api-reference/plotting/timeseries-plots) | Time series plots                                             |
| [`Table`](/api-reference/plotting/tables)                      | Display Series as Interactive table in a Div                  |

### Serialization / IO / conversion

|                                                               |                                              |
| ------------------------------------------------------------- | -------------------------------------------- |
| [`Series.toCSV`](/api-reference/dataframe/dataframe.to_csv)   | Convert DataFrame or Series to CSV.          |
| [`Series.toJSON`](/api-reference/dataframe/dataframe.to_json) | Convert DataFrame or Series to a JSON.       |
| Series.toExcel                                                | Convert DataFrame or Series to an excel file |


# Creating a Series

danfo.**Series**(data, options)

| Parameters | Type                              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| data       | 1D Array, 1D Tensor, JSON object. | Flat data structure to load into DataFrame                                                                                                                                                                                                                                                                                                                                                                                                                   |
| options    | Object                            | <p>Optional configuration object. Supported properties are:<br></p><p><strong>index:</strong> Array of numeric or string names for subseting array. If not specified, indexes are auto-generated.<br></p><p><strong>dtypes:</strong> Array of data types for each the column. If not specified, dtypes are/is inferred.<br></p><p><strong>config</strong>: General configuration object for extending or setting NDframe behavior. See full options here</p> |

In order to create a Series, you need to call the new Keyword and pass a flat data structure. In the following examples, we show you how to create a Series by specifying different config options.

### Creating a Series from an object:

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

obj_data = { 'B': ["bval1", "bval2", "bval3", "bval4"] }
df = new dfd.Series(obj_data)
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

         json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
            { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
            { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
            { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```javascript
╔═══╤═══════╗
║ 0 │ bval1 ║
╟───┼───────╢
║ 1 │ bval2 ║
╟───┼───────╢
║ 2 │ bval3 ║
╟───┼───────╢
║ 3 │ bval4 ║
╚═══╧═══════╝
```

### Creating a Series from an array

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

obj_data = ["bval1", "bval2", "bval3", "bval4"]
df = new dfd.Series(obj_data)
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>    <title>Document</title>
</head>

<body>

    <script>

         json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
            { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
            { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
            { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }]

        df = new dfd.DataFrame(json_data)
        df.print()

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

```
╔═══╤═══════╗
║ 0 │ bval1 ║
╟───┼───────╢
║ 1 │ bval2 ║
╟───┼───────╢
║ 2 │ bval3 ║
╟───┼───────╢
║ 3 │ bval4 ║
╚═══╧═══════╝
```

### Creating a Series and specifying index and dtypes

You can create a Series and specify options like index, dtypes, as well as configuration options for display, and memory mode etc.

> Note: Specifing dtypes, and index on Series creation makes the process slightly faster.

{% tabs %}
{% tab title="Node" %}

```javascript
import { Series } from "danfojs"

let data1 = [1, 2, 3, 4, 5];
let index = ["a", "b", "c", "d", "e"];
let dtypes = ["int32",]

let df = new Series(data1, { index, dtypes });
df.print()
```

{% endtab %}
{% endtabs %}

```
╔═══╤═══╗
║ a │ 1 ║
╟───┼───╢
║ b │ 2 ║
╟───┼───╢
║ c │ 3 ║
╟───┼───╢
║ d │ 4 ║
╟───┼───╢
║ e │ 5 ║
╚═══╧═══╝
```

### Creating a Series and specifying memory mode

To use less space on Series creation, you can set the low memory mode as demonstrated below:

```javascript
import { Series } from "danfojs"

let data1 = [1, 2.3, 3, 4, 5, "girl"];

let df = new Series(data1, {
    config: { lowMemoryMode: true }
});
df.print()
```

{% hint style="info" %}
**Note**: In low memory mode, less space is used by the Series.
{% endhint %}


# Series.append

Add a new value or values to the end of a Series.

danfo.Series.**append**(newValue, index, options)

| Parameters | Type          | Description                                                                                                                | Default |
| ---------- | ------------- | -------------------------------------------------------------------------------------------------------------------------- | ------- |
| newValue   | Array, Series | Object to append                                                                                                           |         |
| index      | Array         | The new index value(s) to append to the Series. Must contain the same number of values as `newValues` as they map `1 - 1`. |         |
| options    | Object        | <p>{<br><strong>inplace</strong>: Whether to perform operation in-place or not.</p><p>}</p>                                | false   |

### **Append new Series to the end of a Series**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf1 = new dfd.Series([1, 2, 3, 4], { index: ['f1', 'f2', 'f3', 'f4'] })
let sf2 = new dfd.Series(["a", "b", "c"])

new_sf = sf1.append(sf2, ["f5", "f6", "f7"])
new_sf.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔════╤═══╗
║ f1 │ 1 ║
╟────┼───╢
║ f2 │ 2 ║
╟────┼───╢
║ f3 │ 3 ║
╟────┼───╢
║ f4 │ 4 ║
╟────┼───╢
║ f5 │ a ║
╟────┼───╢
║ f6 │ b ║
╟────┼───╢
║ f7 │ c ║
╚════╧═══╝
```

{% endtab %}
{% endtabs %}

### **Append new Series to the end of a Series in-place**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf1 = new dfd.Series([1, 2, 3, 4], { index: ['f1', 'f2', 'f3', 'f4'] })
let sf2 = new dfd.Series(["a", "b", "c"])
let newIndex = ["f5", "f6", "f7"]

sf1.append(sf2, newIndex, { inplace: true })
sf1.print()
```

{% endtab %}
{% endtabs %}

```
╔════╤═══╗
║ f1 │ 1 ║
╟────┼───╢
║ f2 │ 2 ║
╟────┼───╢
║ f3 │ 3 ║
╟────┼───╢
║ f4 │ 4 ║
╟────┼───╢
║ f5 │ a ║
╟────┼───╢
║ f6 │ b ║
╟────┼───╢
║ f7 │ c ║
╚════╧═══╝
```

### **Append an array to the end of Series**

{% tabs %}
{% tab title="Node" %}

```javascript
let sf1 = new dfd.Series([1, 2, 3, 4], { index: ['f1', 'f2', 'f3', 'f4'] })
let sfArr = ["a", "b", "c"]

new_sf = sf1.append(sfArr, ["f5", "f6", "f7"])
new_sf.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔════╤═══╗
║ f1 │ 1 ║
╟────┼───╢
║ f2 │ 2 ║
╟────┼───╢
║ f3 │ 3 ║
╟────┼───╢
║ f4 │ 4 ║
╟────┼───╢
║ f5 │ a ║
╟────┼───╢
║ f6 │ b ║
╟────┼───╢
║ f7 │ c ║
╚════╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.cumSum

Return a cumulative sum of a series

> danfo.Series.**cumSum**(options)

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.cumSum().print()
```

{% endtab %}

{% tab title="Browser" %}

```markup
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/danfojs@0.2.4/dist/index.min.js"></script>
    <title>Document</title>
</head>

<body>

    <script>

      //danfo is exposed on dfd namespace 
      s = new dfd.Series([1,2,3,4,5]) 

    </script>

</body>

</html>
```

{% endtab %}
{% endtabs %}

```
╔═══╤═════╗
║ 0 │ 10  ║
╟───┼─────╢
║ 1 │ 55  ║
╟───┼─────╢
║ 2 │ 111 ║
╟───┼─────╢
║ 3 │ 136 ║
╟───┼─────╢
║ 4 │ 159 ║
╟───┼─────╢
║ 5 │ 179 ║
╟───┼─────╢
║ 6 │ 189 ║
╚═══╧═════╝
```


# Series.cumMax

Returns cumulative maximum over a series

> danfo.Series.**cumMax**(options)

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.cumMax().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 3 │ 56 ║
╟───┼────╢
║ 4 │ 56 ║
╟───┼────╢
║ 5 │ 56 ║
╟───┼────╢
║ 6 │ 56 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}


# Series.cumProd

Return the cumulative product of a series

> danfo.Series.**cumProd**()

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.cumProd().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════════════╗
║ 0 │ 10         ║
╟───┼────────────╢
║ 1 │ 450        ║
╟───┼────────────╢
║ 2 │ 25200      ║
╟───┼────────────╢
║ 3 │ 630000     ║
╟───┼────────────╢
║ 4 │ 14490000   ║
╟───┼────────────╢
║ 5 │ 289800000  ║
╟───┼────────────╢
║ 6 │ 2898000000 ║
╚═══╧════════════╝
```

{% endtab %}
{% endtabs %}


# Series.cumMin

Returns the cumulative min of a Series

> danfo.Series.**cumMin**(options)

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let data1 = [10, 45, 56, 5, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.cumMin().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 10 ║
╟───┼────╢
║ 2 │ 10 ║
╟───┼────╢
║ 3 │ 5  ║
╟───┼────╢
║ 4 │ 5  ║
╟───┼────╢
║ 5 │ 5  ║
╟───┼────╢
║ 6 │ 5  ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}


# Series.str.split

Split string around a given separator/delimiter. The array of strings are then converted to a string.

> danfo.Series.str.**split**(splitVal, options)

| Parameters | Type   | Description                                                | Default                         |
| ---------- | ------ | ---------------------------------------------------------- | ------------------------------- |
| splitVal   | String | separator or delimiter used to split the string            | " "                             |
| options    | Object | **inplace**: Whether to perform operation in-place or not. | <p>{<br>inplace: false<br>}</p> |

**Examples**

Split the string value in the Series by space and obtain the Series values

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const dfd = require("danfojs-node")

let data = ["king of the music","the lamba queen","I love the hat"]
let sf = new dfd.Series(data)
console.log(sf.str.split().values)
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

**OUTPUT:** `[ 'king,of,the,music', 'the,lamba,queen', 'I,love,the,hat' ]`

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const dfd = require("danfojs-node")

let data = ["king_of_the_music","the_lamba_queen","I_love_the_hat"]
let sf = new dfd.Series(data)
sf.str.split("_").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ king,of,the,music    ║
╟───┼──────────────────────╢
║ 1 │ the,lamba,queen      ║
╟───┼──────────────────────╢
║ 2 │ I,love,the,hat       ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.len

Obtain the length of each string element in a Series

> danfo.Series.str.**len**(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L324)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Examples**

Returns the length (number of character) of a string, and also return the length (number of elements) of Array

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const dfd = require("danfojs-node")

let data = ["dog", 5,"cat","fog","mug","animals"]
let sf = new dfd.Series(data)
sf.str.len().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══╗
║ 0 │ 3 ║
╟───┼───╢
║ 1 │ 1 ║
╟───┼───╢
║ 2 │ 3 ║
╟───┼───╢
║ 3 │ 3 ║
╟───┼───╢
║ 4 │ 3 ║
╟───┼───╢
║ 5 │ 7 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.str.join

Join a new string value to all string elements in a Series.

> danfo.Series.str.**join**(valToJoin, joinChar, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L308)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| valToJoin  | String | the string value you want to                                   | ""                                                     |
| joinChar   | String | The delimiter to specify the joining                           | " "                                                    |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:**

\*\*\*\* return **Series**

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower part', 'CAPITALS city', 'this is a sentence', 'SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.join("new", "_").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════════════════════════╗
║ 0 │ lower part_new         ║
╟───┼────────────────────────╢
║ 1 │ CAPITALS city_new      ║
╟───┼────────────────────────╢
║ 2 │ this is a sentence_new ║
╟───┼────────────────────────╢
║ 3 │ SwAp CaSe_new          ║
╚═══╧════════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.trim

Remove leading and trailing Whitespace from a String element

> danfo.Series.str.**trim**(options) **\[**[**source**](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L293)**]**

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:**

\*\*\*\* return Series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower part ', ' CAPITALS city', ' this is a sentence', '  SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.trim().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ lower part           ║
╟───┼──────────────────────╢
║ 1 │ CAPITALS city        ║
╟───┼──────────────────────╢
║ 2 │ this is a sentence   ║
╟───┼──────────────────────╢
║ 3 │ SwAp CaSe            ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.substring

Obtain the substring of each element in a series

> danfo.Series.str.**substring**(startIndex, endIndex, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L280)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| startIndex | Number | specify the index to start obtaining the substring             | 0                                                      |
| endIndex   | Number | specify the index to end the substring                         | 1                                                      |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**

\*\*\*\* return **Series**

**Example**

Obtain the substring from index 2 to index 4 of the string elements in a Series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower part ', ' CAPITALS city', ' this is a sentence', '  SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.substring(2, 4).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ we                   ║
╟───┼──────────────────────╢
║ 1 │ AP                   ║
╟───┼──────────────────────╢
║ 2 │ hi                   ║
╟───┼──────────────────────╢
║ 3 │ Sw                   ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.substr

Obtain the substring from a String element in a Series, by specifying the number of string to obtain starting from a specific index.

> danfo.Series.str.substr(startIndex, num, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L265)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| startIndex | Number | specify the index to start obtaining the substring             | 0                                                      |
| num        | Number | The number of character to obtain starting from the startIndex | 1                                                      |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:**

\*\*\*\* return Series

**Example**

Obtain substring( containing 4 characters) starting from the third character (2nd index).

```javascript
const dfd = require("danfojs-node")

let data = ['lower part ', ' CAPITALS city', ' this is a sentence', '  SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.substr(2, 4).print()
```

{% tabs %}
{% tab title="Output" %}

```javascript
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ wer                  ║
╟───┼──────────────────────╢
║ 1 │ APIT                 ║
╟───┼──────────────────────╢
║ 2 │ his                  ║
╟───┼──────────────────────╢
║ 3 │ SwAp                 ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.slice

Obtain the substring of each element in a series

> danfo.Series.str.slice(startIndex, endIndex, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L235)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| startIndex | Number | specify the index to start obtaining the substring             | 0                                                      |
| endIndex   | Number | specify the index to end the substring                         | 1                                                      |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:**

\*\*\*\* return Series.

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower part ', ' CAPITALS city', ' this is a sentence', '  SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.slice(2, 4).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ we                   ║
╟───┼──────────────────────╢
║ 1 │ AP                   ║
╟───┼──────────────────────╢
║ 2 │ hi                   ║
╟───┼──────────────────────╢
║ 3 │ Sw                   ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.search

Obtain the index position of a searched  character in a String

> danfo.Series.str.**search**(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L220)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| str        | String | the string to search for                                       | ""                                                     |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:**

\*\*\*\* return Series: Series of index position

**Example**

obtain the index position for a character

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower part ', ' CAPITALS city', ' this is a sentence', '  SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.search("S").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ -1                   ║
╟───┼──────────────────────╢
║ 1 │ 8                    ║
╟───┼──────────────────────╢
║ 2 │ -1                   ║
╟───┼──────────────────────╢
║ 3 │ 2                    ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}

Obtain the index position for a searched word

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower city ', ' CAPITALS city', ' this is a sentence', '  SwAp CaSe']
let sf = new dfd.Series(data)
sf.str.search("city").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 6                    ║
╟───┼──────────────────────╢
║ 1 │ 10                   ║
╟───┼──────────────────────╢
║ 2 │ -1                   ║
╟───┼──────────────────────╢
║ 3 │ -1                   ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.repeat

Repeat the the character(s) in a string for a specified number of time

> danfo.Series.str.**repeat**(num, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L205)]

| Parameters | Type    | Description                                                    | Default                                                |
| ---------- | ------- | -------------------------------------------------------------- | ------------------------------------------------------ |
| num        | integer | the string to search for                                       | 1                                                      |
| options    | Object  | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:** Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['a', 'b', 'c', 'd']
let sf = new dfd.Series(data)
sf.str.repeat(4).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ aaaa                 ║
╟───┼──────────────────────╢
║ 1 │ bbbb                 ║
╟───┼──────────────────────╢
║ 2 │ cccc                 ║
╟───┼──────────────────────╢
║ 3 │ dddd                 ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.replace

Replace a word or character(s) in a String element

> danfo.Series.str.replace(searchValue, replaceValue, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L191)]

| Parameters   | Type   | Description                                                    | Default                                                |
| ------------ | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| searchValue  | string | String \| Character value to replace. Supports regex.          | ""                                                     |
| replaceValue | String | string to replace the searched string                          | ""                                                     |
| options      | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:** Series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.replace("A", "XXX").print()
```

{% endtab %}

{% tab title="Browse" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ lower                ║
╟───┼──────────────────────╢
║ 1 │ CXXXPITALS           ║
╟───┼──────────────────────╢
║ 2 │ this is a sentence   ║
╟───┼──────────────────────╢
║ 3 │ SwXXXpCaSe           ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.lastIndexOf

Obtain the position of the last found occurrence of a specified value in a string

danfo.Series.str.lastIndexOf(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L175)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| str        | string | the string to search for                                       | ""                                                     |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**: Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.lastIndexOf("r").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 4                    ║
╟───┼──────────────────────╢
║ 1 │ -1                   ║
╟───┼──────────────────────╢
║ 2 │ -1                   ║
╟───┼──────────────────────╢
║ 3 │ -1                   ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.indexOf

the position of the first found occurrence of a specified value in a string

> danfo.Series.str.indexOf(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L161)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| str        | string | the string to obtain its index                                 | ""                                                     |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:** Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.indexOf("C").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ -1                   ║
╟───┼──────────────────────╢
║ 1 │ 0                    ║
╟───┼──────────────────────╢
║ 2 │ -1                   ║
╟───┼──────────────────────╢
║ 3 │ 4                    ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.includes

Checks whether a string contains the specified string/characters

> danfo.Series.str.includes(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L147)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| str        | string | the character(s) to check                                      | ""                                                     |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**: Series (boolean element)

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.includes("C").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ false                ║
╟───┼──────────────────────╢
║ 1 │ true                 ║
╟───┼──────────────────────╢
║ 2 │ false                ║
╟───┼──────────────────────╢
║ 3 │ true                 ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.endsWith

Checks whether a string ends with specified characters

> danfo.Series.str.**endsWith**(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L133)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| str        | string | the character(s) to check                                      | ""                                                     |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**: Series (Boolean element)

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.endsWith("e").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ false                ║
╟───┼──────────────────────╢
║ 1 │ false                ║
╟───┼──────────────────────╢
║ 2 │ true                 ║
╟───┼──────────────────────╢
║ 3 │ true                 ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.startsWith

Test whether a string begins with specified characters

> danfo.Series.str.**startsWith**(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L119)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| str        | string | the character(s) to check                                      | ""                                                     |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:** Series (Boolean element)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.startsWith("S").print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ false                ║
╟───┼──────────────────────╢
║ 1 │ false                ║
╟───┼──────────────────────╢
║ 2 │ false                ║
╟───┼──────────────────────╢
║ 3 │ true                 ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.concat

Joins two or more strings/arrays

> danfo.Series.str.**concat**(other, position, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L80)]

| Parameters | Type            | Description                                                                                                                                                                                  | Default                                                |
| ---------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| other      | string or Array | string or list of strings to add to each string element of the series                                                                                                                        | ""                                                     |
| position   | Int             | The position to add the **other** (string or array) is either 0 or 1. 0 is to add the other at the beginning of each of the string element, and 1 is to add to the end of the string element | 1                                                      |
| options    | Object          | **inplace**: Whether to perform the operation in-place or not.                                                                                                                               | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns:** Series (String element)

**Examples**

Add the strings from an Array to the start of each of the String element in Series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'CAPITALS', 'sentence', 'SwApCaSe']
let data2 = ['XX', 'YY', 'BB', '01']
let sf = new dfd.Series(data)
sf.str.concat(data2,0).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ XXlower boy          ║
╟───┼──────────────────────╢
║ 1 │ YYCAPITALS           ║
╟───┼──────────────────────╢
║ 2 │ BBsentence           ║
╟───┼──────────────────────╢
║ 3 │ 01SwApCaSe           ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}

Add the strings from an Array to the end of each of the String element in Series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'CAPITALS', 'sentence', 'SwApCaSe']
let data2 = ['XX', 'YY', 'BB', '01']
let sf = new dfd.Series(data)
sf.str.concat(data2,1).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ lower boyXX          ║
╟───┼──────────────────────╢
║ 1 │ CAPITALSYY           ║
╟───┼──────────────────────╢
║ 2 │ sentenceBB           ║
╟───┼──────────────────────╢
║ 3 │ SwApCaSe01           ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}

Add a string to the start of each string element in a Series

{% tabs %}
{% tab title="Output" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'CAPITALS', 'sentence', 'SwApCaSe']
let data2 = ['XX', 'YY', 'BB', '01']
let sf = new dfd.Series(data)
sf.str.concat("pre",0).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ prelower boy         ║
╟───┼──────────────────────╢
║ 1 │ preCAPITALS          ║
╟───┼──────────────────────╢
║ 2 │ presentence          ║
╟───┼──────────────────────╢
║ 3 │ preSwApCaSe          ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}

Add a string to the end of each string element in a series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'CAPITALS', 'sentence', 'SwApCaSe']
let data2 = ['XX', 'YY', 'BB', '01']
let sf = new dfd.Series(data)
sf.str.concat("post",1).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ lower boypost        ║
╟───┼──────────────────────╢
║ 1 │ CAPITALSpost         ║
╟───┼──────────────────────╢
║ 2 │ sentencepost         ║
╟───┼──────────────────────╢
║ 3 │ SwApCaSepost         ║
╚═══╧══════════════════════╝
```


# Series.str.charAt

Obtain the character at the specified index (position)

> danfo.Series.str.**charAt**(index) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L64)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| index      | int    | the index at which to obtain the character                     | 0                                                      |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**: Series (Character element)

**Example**

Obtain the character at index 2 of all string elements in the series.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'CAPITALS', 'sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.charAt(2).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ w                    ║
╟───┼──────────────────────╢
║ 1 │ P                    ║
╟───┼──────────────────────╢
║ 2 │ n                    ║
╟───┼──────────────────────╢
║ 3 │ A                    ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.toUpperCase

Converts all characters to uppercase.

> danfo.Series.str.toUpperCase(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L33)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**: Series (String element)

**Example**

Convert all characters in each string element to capital letter

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'CAPITALS', 'sentence', 'SwApCaSe']
let sf = new dfd.Series(data)
sf.str.toUpperCase().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ LOWER BOY            ║
╟───┼──────────────────────╢
║ 1 │ CAPITALS             ║
╟───┼──────────────────────╢
║ 2 │ SENTENCE             ║
╟───┼──────────────────────╢
║ 3 │ SWAPCASE             ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.toLowerCase

Converts all characters to lower case.

> danfo.Series.str.toLowerCase(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L20)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Example**

Convert all characters in each string element to small letter

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['LOWER BOY', 'CAPITALS', 'SENTENCE', 'SWAPCASE']
let sf = new dfd.Series(data)
sf.str.toLowerCase().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ lower boy            ║
╟───┼──────────────────────╢
║ 1 │ capitals             ║
╟───┼──────────────────────╢
║ 2 │ sentence             ║
╟───┼──────────────────────╢
║ 3 │ swapcase             ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.str.capitalize

Capitalize the first character of each string

> danfo.Series.str.**capitalize**(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L46)]

| Parameters | Type   | Description                                                    | Default                                                |
| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ |
| options    | Object | **inplace**: Whether to perform the operation in-place or not. | <p>{</p><p><strong>inplace</strong>: false</p><p>}</p> |

**Returns**: Series (String element)

**Example**

Convert the first character of a string to capital letter

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ['lower boy', 'capitals', 'sentence', 'swApCaSe']
let sf = new dfd.Series(data)
sf.str.capitalize().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ Lower boy            ║
╟───┼──────────────────────╢
║ 1 │ Capitals             ║
╟───┼──────────────────────╢
║ 2 │ Sentence             ║
╟───┼──────────────────────╢
║ 3 │ Swapcase             ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.dt.seconds

Obtain the seconds in Date series

> danfo.Series.dt.**seconds**()

**Parameters**: None

**Returns:** Series (Int elements)

**Example**

Obtain the seconds of the datetime

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"s"})
let sf = new dfd.Series(data)
//print the series frame
sf.print()

//print the seconds obtained
sf.dt.seconds().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║ 0 │ 1/1/2000, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 1/1/2000, 1:00:01 AM ║
╟───┼──────────────────────╢
║ 2 │ 1/1/2000, 1:00:02 AM ║
╚═══╧══════════════════════╝

╔═══╤═══╗
║ 0 │ 0 ║
╟───┼───╢
║ 1 │ 1 ║
╟───┼───╢
║ 2 │ 2 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.dt.minutes

Obtain the minutes in a Time Series

> danfo.Series.dt.**minutes**() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L292)]

**Parameters**: None

**Returns:** Series (int Elements)

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"m"})
let sf = new dfd.Series(data)
//print the series
sf.print()
//print the minutes series
sf.dt.minutes().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 1/1/2000, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 1/1/2000, 1:01:00 AM ║
╟───┼──────────────────────╢
║ 2 │ 1/1/2000, 1:02:00 AM ║
╚═══╧══════════════════════╝

//print the minutes series
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 0                    ║
╟───┼──────────────────────╢
║ 1 │ 1                    ║
╟───┼──────────────────────╢
║ 2 │ 2                    ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.dt.dayOfMonth

Obtain the day of the month

> danfo.Series.dt.dayOfMonth() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L268)]

**Parameters:** None

**Returns**: Series (Int elements)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":"2000-01-01", period:4, freq:"D"})
let sf = new dfd.Series(data)
//print series
sf.print()
//print monthdays
sf.dt.dayOfMonth().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║ 0 │ 1/1/2000, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 1/2/2000, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 2 │ 1/3/2000, 1:00:00 AM ║
╚═══╧══════════════════════╝

╔═══╤═══╗
║ 0 │ 1 ║
╟───┼───╢
║ 1 │ 2 ║
╟───┼───╢
║ 2 │ 3 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.dt.monthName

obtain the month name in a Time Series

> danfo.Series.dt.monthName() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L241)]

**Parameters**: None

**Returns:** Series (String elements)

**Examples**

{% tabs %}
{% tab title="Output" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.date_range({"start":'2018-01', freq:'M', period:3})
let sf = new dfd.Series(data)
//print series
sf.print()
//print month names
sf.dt.monthName().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║ 0 │ 1/1/2018, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 2/1/2018, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 2 │ 3/1/2018, 1:00:00 AM ║
╚═══╧══════════════════════╝

╔═══╤═════╗
║ 0 │ Jan ║
╟───┼─────╢
║ 1 │ Feb ║
╟───┼─────╢
║ 2 │ Mar ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}


# Series.dt.hours

Obtain the hours in a time series

> danfo.Series.dt.**hours**()

**Parameters:** None

**Returns:** Series (int elements)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"H"})
let sf = new dfd.Series(data)
// print series
sf.print()
// print hour series
sf.dt.hours().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║ 0 │ 1/1/2000, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 1/1/2000, 2:00:00 AM ║
╚═══╧══════════════════════╝

╔═══╤═══╗
║ 0 │ 1 ║
╟───┼───╢
║ 1 │ 2 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.dt.dayOfWeek

Obtain the days of the weeks

> danfo.Series.dt.dayOfWeek() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L255)]

**Parameters**: None

**Returns:** Series (String elements)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":'2016-12-31', "end":'2018-01-08'})
let sf = new dfd.Series(data)
//print series
sf.print()
//print days of the week
sf.dt.dayOfWeek().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

```
╔═══╤════════════════════════╗
║ 0 │ 12/31/2016, 1:00:00 AM ║
╟───┼────────────────────────╢
║ 1 │ 1/1/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 2 │ 1/2/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 3 │ 1/3/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 4 │ 1/4/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 5 │ 1/5/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 6 │ 1/6/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 7 │ 1/7/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 8 │ 1/8/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 9 │ 1/9/2017, 1:00:00 AM   ║
╚═══╧════════════════════════╝

╔═══╤═══╗
║ 0 │ 6 ║
╟───┼───╢
║ 1 │ 0 ║
╟───┼───╢
║ 2 │ 1 ║
╟───┼───╢
║ 3 │ 2 ║
╟───┼───╢
║ 4 │ 3 ║
╟───┼───╢
║ 5 │ 4 ║
╟───┼───╢
║ 6 │ 5 ║
╟───┼───╢
║ 7 │ 6 ║
╟───┼───╢
║ 8 │ 0 ║
╟───┼───╢
║ 9 │ 1 ║
╚═══╧═══╝
```


# Series.dt.dayOfWeek

Obtain the numerical representation of the week day.

> danfo.Series.dt.dayOfWeek() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L216)]

**Parameters**: None

**Returns:** Series (int elements)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":'2016-12-31', "end":'2018-01-08'})
let sf = new dfd.Series(data)
//print series
sf.print()
//print days of the week
sf.dt.dayOfWeek().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

```
╔═══╤════════════════════════╗
║ 0 │ 12/31/2016, 1:00:00 AM ║
╟───┼────────────────────────╢
║ 1 │ 1/1/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 2 │ 1/2/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 3 │ 1/3/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 4 │ 1/4/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 5 │ 1/5/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 6 │ 1/6/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 7 │ 1/7/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 8 │ 1/8/2017, 1:00:00 AM   ║
╟───┼────────────────────────╢
║ 9 │ 1/9/2017, 1:00:00 AM   ║
╚═══╧════════════════════════╝

╔═══╤═══╗
║ 0 │ 6 ║
╟───┼───╢
║ 1 │ 0 ║
╟───┼───╢
║ 2 │ 1 ║
╟───┼───╢
║ 3 │ 2 ║
╟───┼───╢
║ 4 │ 3 ║
╟───┼───╢
║ 5 │ 4 ║
╟───┼───╢
║ 6 │ 5 ║
╟───┼───╢
║ 7 │ 6 ║
╟───┼───╢
║ 8 │ 0 ║
╟───┼───╢
║ 9 │ 1 ║
╚═══╧═══╝
```


# Series.dt.month

Obtain the month in a date time series

> danfo.Series.dt.**month**() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L193)]

**Parameters**: None

**Returns:** Series (int elements)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":'2016-7-31', "end":'2016-12-08', freq:"M"})
let sf = new dfd.Series(data)

sf.dt.month().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

```
╔═══╤════╗
║ 0 │ 6  ║
╟───┼────╢
║ 1 │ 7  ║
╟───┼────╢
║ 2 │ 9  ║
╟───┼────╢
║ 3 │ 9  ║
╟───┼────╢
║ 4 │ 11 ║
╟───┼────╢
║ 5 │ 11 ║
╚═══╧════╝
```


# Series.dt.year

Obtain the year in a date time series

> danfo.Series.dt.**year**()

**Parameters**: None

**Returns:** Series (int elements)

**Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"Y"})
let sf = new dfd.Series(data)
sf.print()
sf.dt.year().print()
```

{% endtab %}
{% endtabs %}

```
//print date time series
╔═══╤══════════════════════╗
║ 0 │ 1/1/2000, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 1 │ 1/1/2001, 1:00:00 AM ║
╟───┼──────────────────────╢
║ 2 │ 1/1/2002, 1:00:00 AM ║
╚═══╧══════════════════════╝

╔═══╤══════╗
║ 0 │ 2000 ║
╟───┼──────╢
║ 1 │ 2001 ║
╟───┼──────╢
║ 2 │ 2002 ║
╚═══╧══════╝
```


# Series.argMax

Returns the int position of the largest value in the series

> danfo.Series.argMax()

**Parameters**: None

**Returns**: int

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = [1,30,20,40,50,70,90,200,10,20,12]
let sf = new dfd.Series(data)

sf.argMax()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
7
```

{% endtab %}
{% endtabs %}


# Series.argMin

Returns the int position of the smallest value in the series

> danfo.Series.argMin() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L987)]

**Parameters**: None

**Returns**: int

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = [1,30,20,40,50,70,90,200,10,20,12]
let sf = new dfd.Series(data)

sf.argMin()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
0
```

{% endtab %}
{% endtabs %}


# Series.argSort

Return the integer indices that would sort the Series values

> danfo.Series.argSort(options)

| Parameters | Type   | Description                            | Default                                              |
| ---------- | ------ | -------------------------------------- | ---------------------------------------------------- |
| options    | Object | **ascending**: How to sort the indices | <p>{<br><strong>ascending</strong>: true</p><p>}</p> |

**Returns:** Series (int element)

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = [10, 45, 20, 10, 23, 20, 30, 11]
let sf = new dfd.Series(data)

sf.argSort().print() //defaults to ascending order
sf.argSort({ ascending: false }).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══╗
║ 0 │ 3 ║
╟───┼───╢
║ 1 │ 0 ║
╟───┼───╢
║ 2 │ 7 ║
╟───┼───╢
║ 3 │ 5 ║
╟───┼───╢
║ 4 │ 2 ║
╟───┼───╢
║ 5 │ 4 ║
╟───┼───╢
║ 6 │ 6 ║
╟───┼───╢
║ 7 │ 1 ║
╚═══╧═══╝

╔═══╤═══╗
║ 0 │ 1 ║
╟───┼───╢
║ 1 │ 6 ║
╟───┼───╢
║ 2 │ 4 ║
╟───┼───╢
║ 3 │ 2 ║
╟───┼───╢
║ 4 │ 5 ║
╟───┼───╢
║ 5 │ 7 ║
╟───┼───╢
║ 6 │ 0 ║
╟───┼───╢
║ 7 │ 3 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.replace

Replace values given in replace param with value

> danfo.Series.**replace**(oldValue, newValue, options)

| Parameters   | Type   | Description                                                                       | Default                               |
| ------------ | ------ | --------------------------------------------------------------------------------- | ------------------------------------- |
| **oldValue** | Any    | The value you want to replace.                                                    |                                       |
| **newValue** | Any    | The new value you want to replace with.                                           |                                       |
| options      | Object | **inplace**: Boolean, indicating whether to perform the operation inplace or not. | <p>{</p><p>inplace: false</p><p>}</p> |

**Returns**: Series

**Examples**

### Replace a value in a series and return a new series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf = new dfd.Series(data1)
let sf_rep = sf.replace(10, -50)

sf_rep.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════╗
║ 0 │ -50 ║
╟───┼─────╢
║ 1 │ 45  ║
╟───┼─────╢
║ 2 │ 56  ║
╟───┼─────╢
║ 3 │ 25  ║
╟───┼─────╢
║ 4 │ 23  ║
╟───┼─────╢
║ 5 │ 20  ║
╟───┼─────╢
║ 6 │ -50 ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}

### Replace a value in-place

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf = new dfd.Series(data1)
sf.replace(10, -50, { inplace: true})

sf.print()
```

{% endtab %}
{% endtabs %}

```
╔═══╤═════╗
║ 0 │ -50 ║
╟───┼─────╢
║ 1 │ 45  ║
╟───┼─────╢
║ 2 │ 56  ║
╟───┼─────╢
║ 3 │ 25  ║
╟───┼─────╢
║ 4 │ 23  ║
╟───┼─────╢
║ 5 │ 20  ║
╟───┼─────╢
║ 6 │ -50 ║
╚═══╧═════╝
```


# Series.isNa

Detect Missing values

> danfo.Series.isNa()

**Parameters**: None

**Returns**: Series (Boolean element)

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [NaN, undefined, "girl", "Man"]
let sf = new dfd.Series(data1)

sf.isNa().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.fillNa

Replace all NaN value with specified value

> danfo.Series.fillNa(options)

| Parameters  | Type   | Description                                                                                        | Default                               |
| ----------- | ------ | -------------------------------------------------------------------------------------------------- | ------------------------------------- |
| **value**   | Any    | The value to replace all missing value with.                                                       |                                       |
| **options** | Object | **inplace**: Boolean indicating whether to perform the operation inplace or not. Defaults to false | <p>{</p><p>inplace: false</p><p>}</p> |

**Examples**

### Fill nan value and then return new series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [NaN, 1, 2, 33, 4, NaN, 5, 6, 7, 8]
let sf = new dfd.Series(data1)

let sf_rep = sf.fillNa(-999)

sf_rep.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════╗
║ 0 │ -999 ║
╟───┼──────╢
║ 1 │ 1    ║
╟───┼──────╢
║ 2 │ 2    ║
╟───┼──────╢
║ 3 │ 33   ║
╟───┼──────╢
║ 4 │ 4    ║
╟───┼──────╢
║ 5 │ -999 ║
╟───┼──────╢
║ 6 │ 5    ║
╟───┼──────╢
║ 7 │ 6    ║
╟───┼──────╢
║ 8 │ 7    ║
╟───┼──────╢
║ 9 │ 8    ║
╚═══╧══════╝
```

{% endtab %}
{% endtabs %}

### Fill nan value inplace

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [NaN, 1, 2, 33, 4, undefined, 5, 6, 7, 8]
let sf = new dfd.Series(data1)
sf.fillNa(-999, { inplace: true })

sf.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════╗
║ 0 │ -999 ║
╟───┼──────╢
║ 1 │ 1    ║
╟───┼──────╢
║ 2 │ 2    ║
╟───┼──────╢
║ 3 │ 33   ║
╟───┼──────╢
║ 4 │ 4    ║
╟───┼──────╢
║ 5 │ -999 ║
╟───┼──────╢
║ 6 │ 5    ║
╟───┼──────╢
║ 7 │ 6    ║
╟───┼──────╢
║ 8 │ 7    ║
╟───┼──────╢
║ 9 │ 8    ║
╚═══╧══════╝
```

{% endtab %}
{% endtabs %}


# Series.dropNa

Remove missing values from Series

> danfo.Series.dropNa(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L931)]

| Parameters | Type   | Description                                                                                    | Default                            |
| ---------- | ------ | ---------------------------------------------------------------------------------------------- | ---------------------------------- |
| options    | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false | <p>{<br>inplace: false</p><p>}</p> |

### Drop all missing values and then return New Series.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, undefined, 10, 23, 20, null, 10]
let sf = new dfd.Series(data1)
let sf_rep = sf.dropNa()

sf_rep.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 3 │ 10 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╟───┼────╢
║ 7 │ 10 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

### Drop nan values in-place

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, undefined, 10, 23, 20, undefined, 10]
let sf = new dfd.Series(data1)
sf.dropNa({inplace:true})

sf.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 3 │ 10 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╟───┼────╢
║ 7 │ 10 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}


# Series.dropDuplicates

Remove duplicate rows

> danfo.Series.dropDuplicates(options)

| Parameters | Type   | Description       | Default                                                                                                                                                                                |
| ---------- | ------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| options    | Object | **keep**: "first" | <p>"last", which duplicate value to keep. Defaults to "first".<br><strong>inplace</strong>: Boolean indicating whether to perform the operation in-place or not. Defaults to false</p> |

**Returns:** Series

**Examples**

### Drop duplicate by keeping the first occurrence of the duplicate value

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 10, 23, 20, 10, 10]
let sf = new dfd.Series(data1)
let sf_drop = sf.dropDuplicates()

sf_drop.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

### Drop duplicate and keep only the last duplicated value

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 10, 23, 20, 10, 10]
let sf = new dfd.Series(data1)
let sf_drop = sf.dropDuplicates({ keep: "last" })

sf_drop.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╟───┼────╢
║ 7 │ 10 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

### Remove duplicate value in-place

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = ["A", "A", "A", "B", "B", "C", "C", "D"]
let sf = new dfd.Series(data1)
sf.dropDuplicates({ inplace: true })

sf.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══╗
║ 0 │ A ║
╟───┼───╢
║ 3 │ B ║
╟───┼───╢
║ 5 │ C ║
╟───┼───╢
║ 7 │ D ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.valueCounts

Count the number of occurrence for each element in a Series

> danfo.Series.valueCounts()

**Parameters:** None

**Returns:** Series (int element)

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [1, 2, 3, 4, 5, 6, 7, 8, 1, 1, 22, 8, 5, 5, 5]
let sf = new dfd.Series(data1)

sf.valueCounts().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔════╤═══╗
║ 1  │ 3 ║
╟────┼───╢
║ 2  │ 1 ║
╟────┼───╢
║ 3  │ 1 ║
╟────┼───╢
║ 4  │ 1 ║
╟────┼───╢
║ 5  │ 4 ║
╟────┼───╢
║ 6  │ 1 ║
╟────┼───╢
║ 7  │ 1 ║
╟────┼───╢
║ 8  │ 2 ║
╟────┼───╢
║ 22 │ 1 ║
╚════╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.nUnique

Returns the number of unique values in a series

> danfo.Series.nUnique() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L750)]

**Parameters**: None

**Returns:** int

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [1, 2, 3, 4, 5, 6, 7, 8, 1, 1, 22, 8, 5, 5, 5]
let sf = new dfd.Series(data1)

console.log(sf.nUnique())
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Ouptut" %}

```
9
```

{% endtab %}
{% endtabs %}


# Series.unique

Obtain the unique value in a Series

> danfo.Series.**unique**()

**Parameters**: None

**Returns**: Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [1, 2, 3, 4, 5, 6, 7, 8, 1, 1, 22, 8, 5, 5, 5]
let sf = new dfd.Series(data1)

sf.unique().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 1  ║
╟───┼────╢
║ 1 │ 2  ║
╟───┼────╢
║ 2 │ 3  ║
╟───┼────╢
║ 3 │ 4  ║
╟───┼────╢
║ 4 │ 5  ║
╟───┼────╢
║ 5 │ 6  ║
╟───┼────╢
║ 6 │ 7  ║
╟───┼────╢
║ 7 │ 8  ║
╟───┼────╢
║ 8 │ 22 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}


# Series.abs

Returns the absolute value in a Series

> danfo.Series.**abs**(options)

| Parameters | Type   | Description                                                                                         | Default                               |
| ---------- | ------ | --------------------------------------------------------------------------------------------------- | ------------------------------------- |
| options    | Object | **inplace**: Boolean indicating whether to perform the operation in-place or not. Defaults to false | <p>{</p><p>inplace: false</p><p>}</p> |

**Returns:** Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [-10, 45, 56, -25, 23, -20, 10]
let sf = new dfd.Series(data1)

sf.abs().print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 3 │ 25 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╟───┼────╢
║ 6 │ 10 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}


# Series.ne

Check if all values in a  series is not equal to a value(s)

> danfo.Series.ne(other)

| Parameters | Type                    | Description           | Default |
| ---------- | ----------------------- | --------------------- | ------- |
| other      | Series, Array or number | value to compare with |         |

**Returns**: Series (Boolean element)

**Example**

Compare all the values in a series to that in another series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let data2 = [10, 450, 56, 5, 25, 2, 0]
let sf1 = new dfd.Series(data1)
let sf2 = new dfd.Series(data2)

sf1.ne(sf2).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ false ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ true  ║
╟───┼───────╢
║ 4 │ true  ║
╟───┼───────╢
║ 5 │ true  ║
╟───┼───────╢
║ 6 │ true  ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}

Compare all the values in a Series to a value.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.ne(10).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ false ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ true  ║
╟───┼───────╢
║ 3 │ true  ║
╟───┼───────╢
║ 4 │ true  ║
╟───┼───────╢
║ 5 │ true  ║
╟───┼───────╢
║ 6 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.eq

Check all the values in a series is equal to another value

> danfo.Series.eq(other)

| Parameters | Type                    | Description      | Default |
| ---------- | ----------------------- | ---------------- | ------- |
| other      | Series, Array or number | value to compare |         |

**Returns**: Series (Boolean element)

**Examples**

Compare all the values in a series to another series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let data2 = [10, 450, 56, 5, 25, 2, 0]
let sf1 = new dfd.Series(data1)
let sf2 = new dfd.Series(data2)

sf1.eq(sf2).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ false ║
╟───┼───────╢
║ 2 │ true  ║
╟───┼───────╢
║ 3 │ false ║
╟───┼───────╢
║ 4 │ false ║
╟───┼───────╢
║ 5 │ false ║
╟───┼───────╢
║ 6 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}

Check it all the values are equal to a value

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.eq(10).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ false ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ false ║
╟───┼───────╢
║ 4 │ false ║
╟───┼───────╢
║ 5 │ false ║
╟───┼───────╢
║ 6 │ true  ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.ge

Check if all the values in a series is greater than or equal a value

> danfo.Series.ge(other)

| Parameters | Type                    | Description         | Default |
| ---------- | ----------------------- | ------------------- | ------- |
| other      | Series, Array or number | value(s) to compare |         |

**Returns:** Series (Boolean element)

**Example**

Compare all the values in a Series to the values in another series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let data2 = [10, 450, 56, 5, 25, 2, 0]
let sf1 = new dfd.Series(data1)
let sf2 = new dfd.Series(data2)

sf1.ge(sf2).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ false ║
╟───┼───────╢
║ 2 │ true  ║
╟───┼───────╢
║ 3 │ true  ║
╟───┼───────╢
║ 4 │ false ║
╟───┼───────╢
║ 5 │ true  ║
╟───┼───────╢
║ 6 │ true  ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}

Check if all the value in a Series is greater than or equal to a scalar value.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.ge(20).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ false ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ true  ║
╟───┼───────╢
║ 3 │ true  ║
╟───┼───────╢
║ 4 │ true  ║
╟───┼───────╢
║ 5 │ true  ║
╟───┼───────╢
║ 6 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.le

Check if all the values in a series is less than or equal to a value

> danfo.Series.le(other)

| Parameters | Type                    | Description         | Default |
| ---------- | ----------------------- | ------------------- | ------- |
| other      | Series, Array or number | value(s) to compare |         |

**Returns:** Series (Boolean Element)

**Example**

Check if all the values in a series are less than or equal to a value

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.le(20).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ false ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ false ║
╟───┼───────╢
║ 4 │ false ║
╟───┼───────╢
║ 5 │ true  ║
╟───┼───────╢
║ 6 │ true  ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}

check if all the values in a series are less than equal to values in another series.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let data2 = [10, 450, 56, 5, 25, 2, 0]
let sf1 = new dfd.Series(data1)
let sf2 = new dfd.Series(data2)

sf1.le(sf2).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ true  ║
╟───┼───────╢
║ 3 │ false ║
╟───┼───────╢
║ 4 │ true  ║
╟───┼───────╢
║ 5 │ false ║
╟───┼───────╢
║ 6 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.gt

Check if all the value in a series is greater than a value

> danfo.Series.gt(other)

| Parameters | Type                    | Description         | Default |
| ---------- | ----------------------- | ------------------- | ------- |
| other      | Series, Array or number | value(s) to compare |         |

**Returns**: Series (boolean element)

**Example**

Check if all the values in a series are greater than a value

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.gt(20).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ false ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ true  ║
╟───┼───────╢
║ 3 │ true  ║
╟───┼───────╢
║ 4 │ true  ║
╟───┼───────╢
║ 5 │ false ║
╟───┼───────╢
║ 6 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}

check if all the values in a series are greater than values in another series.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let data2 = [10, 450, 56, 5, 25, 2, 0]
let sf1 = new dfd.Series(data1)
let sf2 = new dfd.Series(data2)

sf1.gt(sf2).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ false ║
╟───┼───────╢
║ 1 │ false ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ true  ║
╟───┼───────╢
║ 4 │ false ║
╟───┼───────╢
║ 5 │ true  ║
╟───┼───────╢
║ 6 │ true  ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.lt

Check if all values in a Series are less than a value.

> danfo.Series.lt(other)

| Parameters | Type                    | Description         | Default |
| ---------- | ----------------------- | ------------------- | ------- |
| other      | Series, Array or number | value(s) to compare |         |

**Returns**: Series (boolean element)

**Example**

Check if all the values in a series are less than a value

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf1 = new dfd.Series(data1)

sf1.lt(20).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ true  ║
╟───┼───────╢
║ 1 │ false ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ false ║
╟───┼───────╢
║ 4 │ false ║
╟───┼───────╢
║ 5 │ false ║
╟───┼───────╢
║ 6 │ true  ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}

check if all the values in a series are less than values in another series.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [10, 45, 56, 25, 23, 20, 10]
let data2 = [10, 450, 56, 5, 25, 2, 0]
let sf1 = new dfd.Series(data1)
let sf2 = new dfd.Series(data2)

sf1.lt(sf2).print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══════╗
║ 0 │ false ║
╟───┼───────╢
║ 1 │ true  ║
╟───┼───────╢
║ 2 │ false ║
╟───┼───────╢
║ 3 │ false ║
╟───┼───────╢
║ 4 │ true  ║
╟───┼───────╢
║ 5 │ false ║
╟───┼───────╢
║ 6 │ false ║
╚═══╧═══════╝
```

{% endtab %}
{% endtabs %}


# Series.iloc

danfo.Series.**iloc**()

| Parameters | Type                  | Description                                                            | Default |
| ---------- | --------------------- | ---------------------------------------------------------------------- | ------- |
| rows       | Array or String slice | Array, string slice, index of row positions boolean mask to filter by. |         |

## **Examples**

`.iloc()` is primarily integer position based (from `0` to `length-1` of the axis).

Allowed inputs are:

* An integer, e.g. `5`.
* A list or array of integers, e.g. `[4, 3, 0]`.
* A boolean mask. E.g \[ true, false, false ]
* A string slice object with ints, e.g. `"1:7"`

***Note:** only \*\*\*\* the start label is included, and the end label is ignored.*

`.iloc` will raise`IndexError` if a requested indexer is out-of-bounds.

### **Indexing specific rows by index**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
s.iloc([0,5]).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 12 ║
╟───┼────╢
║ 5 │ 30 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

### **Index by a slice of row**

The [**iloc**](/api-reference/dataframe/danfo.dataframe.iloc) function also accepts string slices of the form \[start: end], e.g "\[0: 5]". This will return all values from index positions 0 to 4.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
s.iloc(["0:5"]).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════╗
║ 0 │ 12  ║
╟───┼─────╢
║ 1 │ 34  ║
╟───┼─────╢
║ 2 │ 2.2 ║
╟───┼─────╢
║ 3 │ 2   ║
╟───┼─────╢
║ 4 │ 30  ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}

By specifying a start index in a slice, all values after that index are returned.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
s.iloc(["5:"]).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════╗
║ 5 │ 30  ║
╟───┼─────╢
║ 6 │ 2.1 ║
╟───┼─────╢
║ 7 │ 7   ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}

### Slice Series by boolean condition

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
s.iloc(s.gt(20)).print()
```

{% endtab %}
{% endtabs %}

```
╔═══╤════╗
║ 1 │ 34 ║
╟───┼────╢
║ 4 │ 30 ║
╟───┼────╢
║ 5 │ 30 ║
╚═══╧════╝
```


# Series.loc

Access a group of rows by label(s) or a boolean array.

danfo.Series.**loc**()

| Parameters | Type          | Description                                                            | Default |
| ---------- | ------------- | ---------------------------------------------------------------------- | ------- |
| rows       | Array, String | Array, string slice, index of row positions boolean mask to filter by. |         |

## **Examples**

`.loc()` is label position based (from `0` to `length-1` of the row axis).

Allowed inputs are:

* An integer, e.g. `"r1"`.
* A list or array of integers, e.g. `["a", "b", "d"]`.
* A boolean mask. E.g \[ true, false, false ]
* A string slice object with ints, e.g. `[`'`"a":"d"'], ["1:4"]`

***Note:** only \*\*\*\* the start label is included, and the end label is ignored.*

`.loc` will raise a `ValueEror` if a requested label is not found.

### **Indexing by specific row index**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


const data = [12, 34, 2.2, 2, 30, 30, 2.1, 7]
const index = ["a", "b", "c", "d", "e", "f", "g", "h"]
let s = new dfd.Series(data, { index })
s.print()

s.loc(["a", "g"]).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════╗
║ a │ 12  ║
╟───┼─────╢
║ b │ 34  ║
╟───┼─────╢
║ c │ 2.2 ║
╟───┼─────╢
║ d │ 2   ║
╟───┼─────╢
║ e │ 30  ║
╟───┼─────╢
║ f │ 30  ║
╟───┼─────╢
║ g │ 2.1 ║
╟───┼─────╢
║ h │ 7   ║
╚═══╧═════╝

╔═══╤═════╗
║ a │ 12  ║
╟───┼─────╢
║ g │ 2.1 ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}

### **Index by a slice of row**

The **loc** function also accepts string slices of the form \[start: end], e.g **\[\`"a":"e"\`]**. This will return all values from label positions `a` to `e`.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

const data = [12, 34, 2.2, 2, 30, 30, 2.1, 7]
const index = ["a", "b", "c", "d", "e", "f", "g", "h"]
let s = new dfd.Series(data, { index })
s.print()

s.loc([`"a":"e"`]).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════╗
║ a │ 12  ║
╟───┼─────╢
║ b │ 34  ║
╟───┼─────╢
║ c │ 2.2 ║
╟───┼─────╢
║ d │ 2   ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Note that when using loc. We expect you to pass labels in the correct format. That is, string labels must be explicitly quoted. For example, the following loc slice will throw an error:\
`s.loc(["a:e"]).print()`\
For the slice above to work, you must quote each slice, e.g:\
`s.loc(["a":"e"]).print()`\
\
***Inner quotes are not needed for numeric indices!***
{% endhint %}

### By specifying a start index in a slice, all values after that index are returned.

{% tabs %}
{% tab title="Node" %}

```javascript
const data = [12, 34, 2.2, 2, 30, 30, 2.1, 7]
let s = new dfd.Series(data)

s.loc([`1:`]).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════╗
║ 1 │ 34  ║
╟───┼─────╢
║ 2 │ 2.2 ║
╟───┼─────╢
║ 3 │ 2   ║
╟───┼─────╢
║ 4 │ 30  ║
╟───┼─────╢
║ 5 │ 30  ║
╟───┼─────╢
║ 6 │ 2.1 ║
╟───┼─────╢
║ 7 │ 7   ║
╚═══╧═════╝
```

{% endtab %}
{% endtabs %}

### Slice Series by boolean condition

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")


let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
s.loc(s.gt(20)).print()
```

{% endtab %}
{% endtabs %}

```
╔═══╤════╗
║ 1 │ 34 ║
╟───┼────╢
║ 4 │ 30 ║
╟───┼────╢
║ 5 │ 30 ║
╚═══╧════╝
```


# Series.at

Access a single value for a row/column label pair.

> danfo.Series.at(label)

| Parameters | Type   | Description       | Default |
| ---------- | ------ | ----------------- | ------- |
| label      | String | label to index by |         |

**Return:** Scalar

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series(["Apples", "Mango", "Banana", "Pear"],
    { index: ["a", "b", "c", "d"] }
)

sf.at("a")

// "Apples"
```

{% endtab %}
{% endtabs %}


# Series.iat

Access a single value for a row/column pair by integer position.

> danfo.Series.iat(index)

| Parameters | Type   | Description | Default |
| ---------- | ------ | ----------- | ------- |
| index      | Number | index value |         |

**Return:** Scalar

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series(["Apples", "Mango", "Banana", "Pear"],
    { index: ["a", "b", "c", "d"] }
)

sf.iat(1)

// "Mango"
```

{% endtab %}
{% endtabs %}


# Series.ndim

Obtain the dimension of a series

> danfo.Series.ndim

**Parameters:** None

**Returns:** int

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)

console.log(sf1.ndim)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
1
```

{% endtab %}
{% endtabs %}


# Series.shape

Obtain the shape of a Series

> danfo.Series.shape

**Parameters**: None

**Returns**: Array \[int, int]

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)

console.log(sf1.shape)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
[ 4, 1 ]
```

{% endtab %}
{% endtabs %}


# Series.dtype

Obtain the dtype of a series

> danfo.Series.dtype \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L197)]

**Parameters**: None

**Returns:** String

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)

console.log(sf1.dtype)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
float32
```

{% endtab %}
{% endtabs %}


# Series.values

Obtain the values in a series

> danfo.Series.values

**Parameters:** None

**Returns**: Array

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)

console.log(sf1.values)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
[ 30.21091, 40.190901, 3.564, 5.0212 ]
```

{% endtab %}
{% endtabs %}


# Series.tensor

Obtain the tensor representation of the values in a Series

> danfo.Series.tensor

**Parameters**: None

**Returns**: Tensorflow tensor

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)

console.log(sf1.tensor)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
Tensor {
  kept: false,
  isDisposedInternal: false,
  shape: [ 4 ],
  dtype: 'float32',
  size: 4,
  strides: [],
  dataId: {},
  id: 2,
  rankType: '1',
  scopeId: 0
}
```

{% endtab %}
{% endtabs %}


# Series.index

Obtain the index of a Series

> danfo.Series.index

**Returns**: Array

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)

console.log(sf1.index)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
[ 0, 1, 2, 3 ]
```

{% endtab %}
{% endtabs %}


# Series.apply

Invoke a function on each value in a Series.

> danfo.series.**apply**(callable, options)

| Parameters | Type     | Description                                                                                    | Default                               |
| ---------- | -------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- |
| callable   | Function | Function (can be anonymous) to apply                                                           |                                       |
| options    | Object   | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false | <p>{</p><p>inplace: false</p><p>}</p> |

**Returns:**

\*\*\*\* return **Series**

***

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series([1, 2, 3, 4, 5, 6, 7, 8])

let apply_func = (x) => {
    return x + x
}
sf.apply(apply_func).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 0 │ 2  ║
╟───┼────╢
║ 1 │ 4  ║
╟───┼────╢
║ 2 │ 6  ║
╟───┼────╢
║ 3 │ 8  ║
╟───┼────╢
║ 4 │ 10 ║
╟───┼────╢
║ 5 │ 12 ║
╟───┼────╢
║ 6 │ 14 ║
╟───┼────╢
║ 7 │ 16 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series([1, 2, 3, 4, 5, 6, 7, 8])

sf.apply(Math.log).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════════════════════╗
║ 0 │ 0                  ║
╟───┼────────────────────╢
║ 1 │ 0.6931471805599453 ║
╟───┼────────────────────╢
║ 2 │ 1.0986122886681096 ║
╟───┼────────────────────╢
║ 3 │ 1.3862943611198906 ║
╟───┼────────────────────╢
║ 4 │ 1.6094379124341003 ║
╟───┼────────────────────╢
║ 5 │ 1.791759469228055  ║
╟───┼────────────────────╢
║ 6 │ 1.9459101490553132 ║
╟───┼────────────────────╢
║ 7 │ 2.0794415416798357 ║
╚═══╧════════════════════╝
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series(["Rice","Beans","Yam","Banana","Wheat"])

sf.apply((x)=>{
    return x.toLocaleLowerCase()
}).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════════╗
║ 0 │ rice   ║
╟───┼────────╢
║ 1 │ beans  ║
╟───┼────────╢
║ 2 │ yam    ║
╟───┼────────╢
║ 3 │ banana ║
╟───┼────────╢
║ 4 │ wheat  ║
╚═══╧════════╝
```

{% endtab %}
{% endtabs %}


# Series.map

Map the value of a series to a function or Object

> danfo.series.**map**(callable)

| Parameter | Type               | Description                                                                                    | Default                               |
| --------- | ------------------ | ---------------------------------------------------------------------------------------------- | ------------------------------------- |
| callable  | Function or Object | A function or object({})                                                                       |                                       |
| options   | Object             | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false | <p>{</p><p>inplace: false</p><p>}</p> |

**Example**

Mapping the element in a Series words in an Object

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series([1, 2, 3, 4])
let map = { 1: "ok", 2: "okie", 3: "frit", 4: "gop" }
sf.map(map).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════╗
║ 0 │ ok   ║
╟───┼──────╢
║ 1 │ okie ║
╟───┼──────╢
║ 2 │ frit ║
╟───┼──────╢
║ 3 │ gop  ║
╚═══╧══════╝
```

{% endtab %}
{% endtabs %}

Mapping values in a Series to a representation using functions.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let sf = new dfd.Series([1,2,3,4])

sf.map((x)=>{
    return `I have ${x} cat(s)`
}).print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════════════════╗
║ 0 │ I have 1 cat(s) ║
╟───┼─────────────────╢
║ 1 │ I have 2 cat(s) ║
╟───┼─────────────────╢
║ 2 │ I have 3 cat(s) ║
╟───┼─────────────────╢
║ 3 │ I have 4 cat(s) ║
╚═══╧═════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.setIndex

Assign new Index to Series

> danfo.series.setIndex\*\*(options)\*\*

| Parameter | Type   | Description                                                                                    | Default                               |
| --------- | ------ | ---------------------------------------------------------------------------------------------- | ------------------------------------- |
| index     | Array  | new index values                                                                               |                                       |
| options   | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false | <p>{</p><p>inplace: false</p><p>}</p> |

**Returns:** Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = [{ alpha: "A", count: 1 }, { alpha: "B", count: 2 }, { alpha: "C", count: 3 }]
let sf = new dfd.Series(data)
sf.print()

let sf_new = sf.setIndex(["one", "two", "three"])
sf_new.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════════════════════════╗
║ 0 │ {"alpha":"A","count":1} ║
╟───┼─────────────────────────╢
║ 1 │ {"alpha":"B","count":2} ║
╟───┼─────────────────────────╢
║ 2 │ {"alpha":"C","count":3} ║
╚═══╧═════════════════════════╝

╔═══════╤═════════════════════════╗
║ one   │ {"alpha":"A","count":1} ║
╟───────┼─────────────────────────╢
║ two   │ {"alpha":"B","count":2} ║
╟───────┼─────────────────────────╢
║ three │ {"alpha":"C","count":3} ║
╚═══════╧═════════════════════════╝
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = ["Humans","Life","Meaning","Fact","Truth"]
let sf = new dfd.Series(data)
let sf_new = sf.setIndex(["H", "L", "M","F","T"])
sf_new.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═════════╗
║ H │ Humans  ║
╟───┼─────────╢
║ L │ Life    ║
╟───┼─────────╢
║ M │ Meaning ║
╟───┼─────────╢
║ F │ Fact    ║
╟───┼─────────╢
║ T │ Truth   ║
╚═══╧═════════╝
```

{% endtab %}
{% endtabs %}

### Set index in-place

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs")

let data = [1, 2, 3, 4, 5, 6]
let sf = new dfd.Series(data)
sf.setIndex(["one", "two", "three", "four", "five", "six"], { inplace: true })
sf.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══════╤═══╗
║ one   │ 1 ║
╟───────┼───╢
║ two   │ 2 ║
╟───────┼───╢
║ three │ 3 ║
╟───────┼───╢
║ four  │ 4 ║
╟───────┼───╢
║ five  │ 5 ║
╟───────┼───╢
║ six   │ 6 ║
╚═══════╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.resetIndex

Reset the index of a series.

> danfo.series.resetIndex(options)

| Parameters | Type   | Description                                                                                        | Default          |
| ---------- | ------ | -------------------------------------------------------------------------------------------------- | ---------------- |
| options    | Object | **inplace:** Boolean indicating whether to perform the operation inplace or not. Defaults to false | { inplace:false} |

`resetIndex` is useful when the index needs to be treated as a column, or when the index is meaningless and needs to be reset to default, before another operation.

### **Reset index to default values**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")
let data = [20, 30, 40]
let sf = new dfd.Series(data, { index: ["a", "b", "c"] })
sf.print()

let sf_reset = sf.resetIndex()
sf_reset.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ a │ 20 ║
╟───┼────╢
║ b │ 30 ║
╟───┼────╢
║ c │ 40 ║
╚═══╧════╝

╔═══╤════╗
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 2 │ 40 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

### Reset index to new values in-place

{% tabs %}
{% tab title="Node" %}

```javascript
let data = [1, 2, 3, 4, 5, 6]
let sf = new dfd.Series(data, { index: ['a', 'b', 'c', 'd', 'e', 'f'] })
sf.print()

sf.resetIndex({ inplace: true })
sf.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤═══╗
║ a │ 1 ║
╟───┼───╢
║ b │ 2 ║
╟───┼───╢
║ c │ 3 ║
╟───┼───╢
║ d │ 4 ║
╟───┼───╢
║ e │ 5 ║
╟───┼───╢
║ f │ 6 ║
╚═══╧═══╝

╔═══╤═══╗
║ 0 │ 1 ║
╟───┼───╢
║ 1 │ 2 ║
╟───┼───╢
║ 2 │ 3 ║
╟───┼───╢
║ 3 │ 4 ║
╟───┼───╢
║ 4 │ 5 ║
╟───┼───╢
║ 5 │ 6 ║
╚═══╧═══╝
```

{% endtab %}
{% endtabs %}


# Series.describe

Generate descriptive statistics. Descriptive statistics include those that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values

> danfo.Series.describe()

**Parameters:** No parameter

**return:** Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = [1,2,3,4,5,6]
let sf = new dfd.Series(data)
sf.describe().print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔══════════╤════════════════════╗
║ count    │ 6                  ║
╟──────────┼────────────────────╢
║ mean     │ 3.5                ║
╟──────────┼────────────────────╢
║ std      │ 1.8708286933869707 ║
╟──────────┼────────────────────╢
║ min      │ 1                  ║
╟──────────┼────────────────────╢
║ median   │ 3.5                ║
╟──────────┼────────────────────╢
║ max      │ 6                  ║
╟──────────┼────────────────────╢
║ variance │ 3.5                ║
╚══════════╧════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.copy

Makes a deep copy of a Series

> danfo.Series.copy()

**parameter:**

**Return:** Series

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [30.21091, 40.190901, 3.564, 5.0212]
let sf1 = new dfd.Series(data1)
let sf2 = sf1.copy()

sf2.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤══════════════════════╗
║   │ 0                    ║
╟───┼──────────────────────╢
║ 0 │ 30.21091             ║
╟───┼──────────────────────╢
║ 1 │ 40.190901            ║
╟───┼──────────────────────╢
║ 2 │ 3.564                ║
╟───┼──────────────────────╢
║ 3 │ 5.0212               ║
╚═══╧══════════════════════╝
```

{% endtab %}
{% endtabs %}


# Series.sortValues

Sorts a Series in ascending or descending order

> danfo.Series.sortValues(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L511)]

| Parameters | Type   | Description                                                                                                                                                                                                                           | Default                                                   |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| options    | Object | <p><strong>inplace</strong>: Boolean indicating whether to perform the operation in-place or not. Defaults to false</p><p><strong>ascending</strong>: Whether to return sorted values in ascending order or not. Defaults to true</p> | <p>{<br>ascending: true,</p><p>inplace: false</p><p>}</p> |

**Return:** Series

### Sort values in a Series

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)
let sf2 = sf1.sortValues()

sf2.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 7 │ 0  ║
╟───┼────╢
║ 2 │ 1  ║
╟───┼────╢
║ 3 │ 2  ║
╟───┼────╢
║ 8 │ 4  ║
╟───┼────╢
║ 4 │ 4  ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 6 │ 89 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

### Sort Series inplace

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)
sf1.sort_values({ inplace: true })

sf1.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 7 │ 0  ║
╟───┼────╢
║ 2 │ 1  ║
╟───┼────╢
║ 3 │ 2  ║
╟───┼────╢
║ 8 │ 4  ║
╟───┼────╢
║ 4 │ 4  ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 6 │ 89 ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}

Sort Series values in descending order

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)
sf1.sortValues({ "ascending": false, "inplace": true })

sf1.print()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
╔═══╤════╗
║ 6 │ 89 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 4 │ 4  ║
╟───┼────╢
║ 8 │ 4  ║
╟───┼────╢
║ 3 │ 2  ║
╟───┼────╢
║ 2 │ 1  ║
╟───┼────╢
║ 7 │ 0  ║
╚═══╧════╝
```

{% endtab %}
{% endtabs %}


# Series.var

Calculate the variance  of a Series

> danfo.Series.var()

**Parameter:** None

**Return:** Number

**Example**

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)

console.log(sf1.var())
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
968.25
```

{% endtab %}
{% endtabs %}




---

[Next Page](/llms-full.txt/1)

