> For the complete documentation index, see [llms.txt](https://cgps.gitbook.io/data-flo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cgps.gitbook.io/data-flo/reference-guide/create-graph-from-datatable.md).

# create-graph-from-datatable

## Description

<mark style="color:purple;">`create-graph-from-datatable`</mark> *adaptor creates a graph structure from a datatable containing edge data*.

Requires selection of two columns from a datatable - a source and target column.\
By default, directed is FALSE, which creates a graph with no directionality to the connections. When changed to TRUE, the directionality is set as going from the 'source' to 'target' column.

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable containing edge data.

**`from column`**\
Type: `text`\
Required: Yes\
The name of the column containing the origin node of the edge.

**`to column`**\
Type: `text`\
Required: Yes\
The name of the column containing the destination node of the edge.

**`directed`**\
Type: `boolean`\
Required: No\
Specifies whether the graph is directed or not. If unspecified, defaults to `False`.

## Outputs

**`graph`**\
Type: `graph`\
A graph structure defining nodes and edges.

## Examples

### Example 1: Default behaviour.

#### Inputs:

`data`:

| id | from | to |
| -- | ---- | -- |
| 1  | A    | B  |
| 2  | B    | C  |
| 3  | C    | A  |
| 4  | C    | D  |

`from column:` from

`to column:` to

`directed:` false

#### Outputs:

`graph`:

```
{ 
    "nodes": [ 
        { "id": "A" }, 
        { "id": "B" }, 
        { "id": "C" }, 
        { "id": "D" } 
    ], 
    "edges": [ 
        { "id": "edge-1", "from": "A", "to": "B", "direction": "none", "attributes": {} }, 
        { "id": "edge-2", "from": "B", "to": "C", "direction": "none", "attributes": {} }, 
        { "id": "edge-3", "from": "C", "to": "A", "direction": "none", "attributes": {} }, 
        { "id": "edge-4", "from": "C", "to": "D", "direction": "none", "attributes": {} } 
    ] 
} 
```

-> Created an undirected graph from the datatable.

### Example 2: Create a directed graph.

#### Inputs:

`data`:

| id | from | to |
| -- | ---- | -- |
| 1  | A    | B  |
| 2  | B    | C  |
| 3  | C    | A  |
| 4  | C    | D  |

`from column:` from

`to column:` to

`directed:`true

#### Outputs:

`graph`:

```
{ 
    "nodes": [ 
    { "id": "A" }, 
    { "id": "B" }, 
    { "id": "C" }, 
    { "id": "D" } 
    ], 
    "edges": [ 
        { "id": "edge-1", "from": "A", "to": "B", "direction": "forward", "attributes": {} }, 
        { "id": "edge-2", "from": "B", "to": "C", "direction": "forward", "attributes": {} }, 
        { "id": "edge-3", "from": "C", "to": "A", "direction": "forward", "attributes": {} }, 
        { "id": "edge-4", "from": "C", "to": "D", "direction": "forward", "attributes": {} } 
        ] 
} 
```

-> Created a directed graph from the datatable.

## Use Cases

* Converting a datatable to a graph, which can then be converted to DOT format [<mark style="color:purple;">`export-graph-to-dot-file`</mark>](/data-flo/reference-guide/export-graph-to-dot-file.md), which can then be fed into the network argument in the [<mark style="color:purple;">`export-to-microreact-project`</mark>](/data-flo/reference-guide/export-to-microreact-project.md) adaptor.
* Formatting the data from a spreadsheet before exporting as a DOT file (using [<mark style="color:purple;">`export-graph-to-dot-file`</mark>](/data-flo/reference-guide/export-graph-to-dot-file.md) adaptor)
* Preparing data for the [<mark style="color:purple;">`apply-force-directed-layout`</mark>](/data-flo/reference-guide/apply-force-directed-layout.md).
