# DataFrame.setIndex

danfo.DataFrame.setIndex(options) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)]

| Parameters | Type   | Description                                                                                                                                                                                                                                                                                                                                                             | Default                                  |
| ---------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| options    | Object | <p>{</p><p><strong>index</strong>: An array of index values to set.</p><p><strong>column</strong>: A column name to set the index to.</p><p><strong>drop</strong>: Whether to drop the column whose index was set. Defaults to false.</p><p><strong>inplace</strong>: Boolean indicating whether to perform the operation inplace or not. Defaults to false</p><p>}</p> | {**drop**: false, \*\*inplace:\*\*false} |

## **Examples**

### **Setting index to a column in the DataFrame**

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

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

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


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

df.setIndex({column: "A", inplace: true})
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

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

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ a          │ -20               │ 34                │ 20                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b          │ 30                │ 5                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ c          │ 47.3              │ 6                 │ 30                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

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

{% endtab %}
{% endtabs %}

### **Setting index to a column in the DataFrame and dropping the column**

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

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

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


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

df.setIndex({column: "A", drop: true, inplace: true})
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

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

```
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ a          │ -20               │ 34                │ 20                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b          │ 30                │ 5                 │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ c          │ 47.3              │ 6                 │ 30                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

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

{% endtab %}
{% endtabs %}

### **Set index to an array of the same length**

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

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

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


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

let new_index = ["a", "b", "c"]
df.setIndex({index: new_index, inplace: true})
df.print()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

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

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

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ a          │ -20               │ 34                │ 20                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b          │ 30                │ -5                │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ c          │ 47.3              │ 6                 │ 30                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
```

{% endtab %}
{% endtabs %}

**Note:** To reset an index to the default values, use the [DataFrame.resetIndex](/api-reference/dataframe/dataframe.reset_index.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://danfo.jsdata.org/api-reference/dataframe/dataframe.set_index.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
