# danfo.getDummies

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](https://danfo.jsdata.org/api-reference/general-functions/danfo.labelencoder) and [OneHotEncoder](https://danfo.jsdata.org/api-reference/general-functions/danfo.onehotencoder)
{% endhint %}


---

# 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/general-functions/danfo.get_dummies.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.
