# What is the node order of Graph.indegree()?

**URL:** <https://igraph.discourse.group/t/what-is-the-node-order-of-graph-indegree/1442>\
**Category:** Usage\
**Tags:** Python\
**Created:** [19 December 2022 12:10 UTC](https://igraph.discourse.group/t/what-is-the-node-order-of-graph-indegree/1442 "2022-12-19T12:10:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nice](https://avatars.discourse-cdn.com/v4/letter/n/ecc23a/32.png) [@nice](https://igraph.discourse.group/u/nice)\
**Post date:** [19 December 2022 12:10 UTC](https://igraph.discourse.group/t/what-is-the-node-order-of-graph-indegree/1442/1 "2022-12-19T12:10:10Z")

</div>

What is the node order of Graph.indegree() ? Is it the same with Graph vertex dataframe?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 December 2022 13:50 UTC](https://igraph.discourse.group/t/what-is-the-node-order-of-graph-indegree/1442/2 "2022-12-19T13:50:44Z")

</div>

> [@nice](#):
>
> What is the node order of Graph.indegree() ?

igraph identifies vertices with contiguous integers indices starting at 0. All functions that return quantities associated with vertices produce a list ordered the same way as the vertices. You can use the vertex index as and index into the list returned by `Graph.indegree()`. I hope this is clear.

> [@nice](#):
>
> Is it the same with Graph vertex dataframe?

igraph does not use dataframes internally. If you’ve assigned vertex names, you can check the vertex ordering using `g.vs['name']`.

If you assigned names based on a dataframe and the `Graph.DataFrame` method, then the first column was supposed to contain the vertex indices. If these were not in order, then the vertices in the graph won’t follow the same order as in the dataframe either.

---

<div class="post-metadata">

**Author:** ![nice](https://avatars.discourse-cdn.com/v4/letter/n/ecc23a/32.png) [@nice](https://igraph.discourse.group/u/nice)\
**Post date:** [19 December 2022 14:23 UTC](https://igraph.discourse.group/t/what-is-the-node-order-of-graph-indegree/1442/3 "2022-12-19T14:23:16Z")

</div>

Thank you. Then how to get the indegree according to a specific name of a node?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 December 2022 14:42 UTC](https://igraph.discourse.group/t/what-is-the-node-order-of-graph-indegree/1442/4 "2022-12-19T14:42:32Z")

</div>

Pass the name to the `vertices` parameter of the method. See [igraph.GraphBase](https://igraph.readthedocs.io/en/stable/api/igraph.GraphBase.html#degree)

```auto
In [1]: import igraph as ig

In [2]: g = ig.Graph.Formula('a->b<-c')

In [3]: g.vs['name']
Out[3]: ['a', 'b', 'c']

```

Here you can see that vertices 0, 1 and 2 are called `'a'`, `'b'` and `'c'`. In most places you can refer to vertices either by index (also called “vertex ID”) or by name.

```python
In [4]: g.indegree() # degrees of all vertices in order
Out[4]: [0, 2, 0]

In [5]: g.indegree(1) # degree of vertex with ID 1
Out[5]: 2

In [6]: g.indegree('b') # we can also refer to it by name instead of ID
Out[6]: 2

In [7]: g.indegree(['b', 'c']) # get the degrees of two vertices
Out[7]: [2, 0] 

```

Keep in mind that using vertex names is slower than using vertex IDs and doesn’t work reliably if you have duplicate names (which you might create accidentally). There are some places where only vertex IDs work, but names don’t.
