Equivalent of R igraph graph_from_data_frame() function in Python igraph?

Question:

Is there an equivalent of this igraph R function in Python igraph?

graph_from_data_frame(d, directed = TRUE, vertices = NULL)

This function creates an igraph graph from one or two data frames
containing the (symbolic) edge list and edge/vertex attributes.

Asked By: Antoine

||

Answers:

Python does not have data frames so there is no direct equivalent. The closest equivalent could be Graph.DictList, which creates a graph from a list of dictionaries, or Graph.TupleList, which is the same for a list of tuples.

Answered By: Tamás

Right now you can use this:

from igraph import Graph
g = Graph.DataFrame(edges, directed=False, vertices=vertices, use_vids=False)

where "edges" is the dataframe with the edges, vertices are the names that will be used in each vertex, and use_vids if you want to assign indexes to name the edges instead of using the "vertices" data

https://igraph.org/python/api/0.9.7/igraph.Graph.html#DataFrame

Answered By: user2383054
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.